0

我正在寻找此代码的 Jquery 版本:

var tweet = document.getElementById('tweet');
tweet.id = 'tweet_js';
tweet.className = 'hiding';

var slide_timer,
max = tweet.scrollWidth,
slide = function () {
    tweet.scrollLeft += 1;
    if (tweet.scrollLeft < max) {
        slide_timer = setTimeout(slide, 40);
    }
};

tweet.onmouseover = tweet.onmouseout = function (e) {
e = e || window.event;
e = e.type === 'mouseover';
clearTimeout(slide_timer);
tweet.className = e ? '' : 'hiding';
if (e) {
    slide();
} else {
    tweet.scrollLeft = 0;
}
};

这段代码发布在这里:http: //jsfiddle.net/sdleihssirhc/AYYQe/3/ 作为这个问题的答案: CSS/JQuery powered sideways scrolling text on hover

4

2 回答 2

2

我建议你写它;)或者你有什么问题吗?如果您的代码已经可以工作,为什么还要为此使用 jquery?您不会获得任何性能优势或类似的东西。

于 2012-02-12T22:45:01.030 回答
0

如果工作正常,我会按原样使用代码。因为此代码中没有性能增益或行。

如果您想查看它的 jQuery 版本,请点击此处。

var $tweet = $('#tweet');
$tweet.attr({
    id: 'tweet_js',
    class: 'hiding'
});

var slide_timer,
max = $tweet.outerWidth(),
var slide = function () {
    $tweet.scrollLeft($tweet.scrollLeft() + 1);
    if ($tweet.scrollLeft() < max) {
        slide_timer = setTimeout(slide, 40);
    }
};

$tweet.bind('mouseover mouseout', function (e) {
    var isMouseOver = e.type === 'mouseover';
    clearTimeout(slide_timer);
    tweet.toggleClass('hiding', !isMouseOver);
    if (isMouseOver) {
        slide();
    } else {
        $tweet.scrollLeft(0);
    }
});
于 2012-02-12T22:59:33.530 回答