简体   繁体   English

使用Jquery在鼠标悬停时创建标题滑动

[英]Create the title sliding when hover mouse using Jquery

i have h2 tag and have width just 100px but the text content inside h2 tag is more than 100px, i want to show text content appear just in one line. 我有h2标签,宽度仅为100px,但是h2标签内的文本内容大于100px,我想显示文本内容仅显示在一行中。 I want to make it like on brazzers.com, When user hover the mouse on title of post, the long title of post will be sliding to show all. 我想使它像在brazzers.com上一样,当用户将鼠标悬停在帖子标题上时,帖子的长标题将滑动以显示所有内容。 Is there a way to create it using jquery? 有没有一种使用jquery创建它的方法? Sorry about my newbie question 对不起我的新手问题

Seems like this is something you can just do with CSS and hover behaviors 似乎可以通过CSS和悬停行为来完成

#test {
    width:30px;
    overflow:hidden;
    white-space:nowrap;
}
#test:hover
{
    overflow:visible;
}

http://jsfiddle.net/tYEfs http://jsfiddle.net/tYEfs

Also, maybe a nsfw warning on the reference link? 另外,在参考链接上可能有nsfw警告吗?

I would create a div with overflow: hidden and inside this div would be the h2 tag with postion set to relative or absolute (depends on your structure and intended behaviour). 我将创建一个具有溢出的div:隐藏并在该div内是位置设置为相对或绝对(取决于您的结构和预期行为)的h2标签。 As soon as the mouse is over the div I would use http://api.jquery.com/animate/ to animate the css "left" property to a negative value. 鼠标悬停在div上方后,我将使用http://api.jquery.com/animate/将CSS的“ left”属性设置为负值。

PS: Did not check the example, due to being on work ... PS:由于正在工作,因此未检查示例...

Please, try this example: 请尝试以下示例:

http://jsfiddle.net/QKstB/2/ http://jsfiddle.net/QKstB/2/

This is a script: 这是一个脚本:

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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM