使用 jquery 连续选取框文本

发布于 2024-09-02 15:38:56 字数 47 浏览 7 评论 0原文

我有列表项,并且列表项需要使用 jQuery 进行排序。

如何?

I am having the list items and the list items needs to be like marqueed using jQuery.

How?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疑心病 2024-09-09 15:38:56

检查这个:http://wordcrowd.org/index.php?title=Rotating_marquee_with_jQuery_Cycle

jquery 循环插件 http://malsup.com/jquery/cycle/

示例:

<script type="text/javascript">
  $(function() {
    $('#marquee').cycle({ 
      fx: 'fade', 
      pause: 1 
    });
  }); 
</script>

check this : http://wordcrowd.org/index.php?title=Rotating_marquee_with_jQuery_Cycle

jquery cycle plugin http://malsup.com/jquery/cycle/

Example :

<script type="text/javascript">
  $(function() {
    $('#marquee').cycle({ 
      fx: 'fade', 
      pause: 1 
    });
  }); 
</script>
流心雨 2024-09-09 15:38:56

在这里检查一下: http://jsfiddle.net/jithil89/BNBB6/

我有这个例子,其中文本连续滚动并且仅在将鼠标悬停在文本上时暂停。

代码 :

$(document).ready(function () {

//this is the useful function to scroll a text inside an element...

function startScrolling(scroller_obj, velocity, start_from) {
    //bind animation  inside the scroller element
    scroller_obj.bind('marquee', function (event, c) {
        //text to scroll
        var ob = $(this);
        //scroller width
        var sw = parseInt(ob.parent().width());
        //text width
        var tw = parseInt(ob.width());
        //text left position relative to the offset parent
        var tl = parseInt(ob.position().left);
        //velocity converted to calculate duration
        var v = velocity > 0 && velocity < 100 ? (100 - velocity) * 1000 : 5000;
        //same velocity for different text's length in relation with duration
        var dr = (v * tw / sw) + v;
        //is it scrolling from right or left?
        switch (start_from) {
            case 'right':
                //is it the first time?
                if (typeof c == 'undefined') {
                    //if yes, start from the absolute right
                    ob.css({
                        left: sw
                    });
                    sw = -tw;
                } else {
                    //else calculate destination position
                    sw = tl - (tw + sw);
                };
                break;
            default:
                if (typeof c == 'undefined') {
                    //start from the absolute left
                    ob.css({
                        left: -tw
                    });
                } else {
                    //else calculate destination position
                    sw += tl + tw;
                };
        }
        //attach animation to scroller element and start it by a trigger
        ob.animate({
            left: sw
        }, {
            duration: dr,
            easing: 'linear',
            complete: function () {
                ob.trigger('marquee');
            },
            step: function () {
                //check if scroller limits are reached
                if (start_from == 'right') {
                    if (parseInt(ob.position().left) < -parseInt(ob.width())) {
                        //we need to stop and restart animation
                        ob.stop();
                        ob.trigger('marquee');
                    };
                } else {
                    if (parseInt(ob.position().left) > parseInt(ob.parent().width())) {
                        ob.stop();
                        ob.trigger('marquee');
                    };
                };
            }
        });
    }).trigger('marquee');
    //pause scrolling animation on mouse over
    scroller_obj.mouseover(function () {
        $(this).stop();
    });
    //resume scrolling animation on mouse out
    scroller_obj.mouseout(function () {
        $(this).trigger('marquee', ['resume']);
    });
};

//the main app starts here...

//change the cursor type for each scroller
$('.scroller').css("cursor", "pointer");

//settings to pass to function
var scroller = $('.scrollingtext'); // element(s) to scroll
var scrolling_velocity = 80; // 1-99
var scrolling_from = 'right'; // 'right' or 'left'

//call the function and start to scroll..
startScrolling(scroller, scrolling_velocity, scrolling_from);

});

Here check this out: http://jsfiddle.net/jithil89/BNBB6/

I have this example, wherein the text is continuously scrolling and pauses only on hover over the text.

Code :

$(document).ready(function () {

//this is the useful function to scroll a text inside an element...

function startScrolling(scroller_obj, velocity, start_from) {
    //bind animation  inside the scroller element
    scroller_obj.bind('marquee', function (event, c) {
        //text to scroll
        var ob = $(this);
        //scroller width
        var sw = parseInt(ob.parent().width());
        //text width
        var tw = parseInt(ob.width());
        //text left position relative to the offset parent
        var tl = parseInt(ob.position().left);
        //velocity converted to calculate duration
        var v = velocity > 0 && velocity < 100 ? (100 - velocity) * 1000 : 5000;
        //same velocity for different text's length in relation with duration
        var dr = (v * tw / sw) + v;
        //is it scrolling from right or left?
        switch (start_from) {
            case 'right':
                //is it the first time?
                if (typeof c == 'undefined') {
                    //if yes, start from the absolute right
                    ob.css({
                        left: sw
                    });
                    sw = -tw;
                } else {
                    //else calculate destination position
                    sw = tl - (tw + sw);
                };
                break;
            default:
                if (typeof c == 'undefined') {
                    //start from the absolute left
                    ob.css({
                        left: -tw
                    });
                } else {
                    //else calculate destination position
                    sw += tl + tw;
                };
        }
        //attach animation to scroller element and start it by a trigger
        ob.animate({
            left: sw
        }, {
            duration: dr,
            easing: 'linear',
            complete: function () {
                ob.trigger('marquee');
            },
            step: function () {
                //check if scroller limits are reached
                if (start_from == 'right') {
                    if (parseInt(ob.position().left) < -parseInt(ob.width())) {
                        //we need to stop and restart animation
                        ob.stop();
                        ob.trigger('marquee');
                    };
                } else {
                    if (parseInt(ob.position().left) > parseInt(ob.parent().width())) {
                        ob.stop();
                        ob.trigger('marquee');
                    };
                };
            }
        });
    }).trigger('marquee');
    //pause scrolling animation on mouse over
    scroller_obj.mouseover(function () {
        $(this).stop();
    });
    //resume scrolling animation on mouse out
    scroller_obj.mouseout(function () {
        $(this).trigger('marquee', ['resume']);
    });
};

//the main app starts here...

//change the cursor type for each scroller
$('.scroller').css("cursor", "pointer");

//settings to pass to function
var scroller = $('.scrollingtext'); // element(s) to scroll
var scrolling_velocity = 80; // 1-99
var scrolling_from = 'right'; // 'right' or 'left'

//call the function and start to scroll..
startScrolling(scroller, scrolling_velocity, scrolling_from);

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文