我有 h2 标签,宽度只有 100px,但 h2 标签内的文本内容超过 100px,我想显示文本内容只出现在一行中。我想让它像 brazzers.com 一样,当用户将鼠标悬停在帖子标题上时,帖子的长标题将滑动显示所有内容。有没有办法使用 jquery 创建它?抱歉我的新手问题
最佳答案
请试试这个例子:
这是一个脚本:
var textWidth = $('h1 nobr').outerWidth(),
totalWidth = $('h1').outerWidth(),
diff = totalWidth - textWidth;
$('h1').hover( function() {
$('h1 nobr').animate({ 'margin-left': diff }, 5000, function() {
$(this).css('margin-left', 0)
});
}, function() {
$('h1 nobr').stop(true, true);
});
关于javascript - 使用 Jquery 鼠标悬停时创建标题滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15646172/