admin管理员组文章数量:1334328
I have a large paragraph. Within that there is a span tag with id for a particular word. On mouse hover the size of that particular word in para should increase. It can e above the other text and cover the contents in paragraph but it should not affect the alignment of other text.
I have a large paragraph. Within that there is a span tag with id for a particular word. On mouse hover the size of that particular word in para should increase. It can e above the other text and cover the contents in paragraph but it should not affect the alignment of other text.
Share Improve this question asked Sep 6, 2010 at 12:21 Akhil K NambiarAkhil K Nambiar 3,97514 gold badges49 silver badges87 bronze badges 1- well i dint try much.... i was thinking to use hover to increase size but that could affect the size. So i posted it here – Akhil K Nambiar Commented Sep 7, 2010 at 4:50
4 Answers
Reset to default 4Like this:
var clone;
$("span").hover(function() {
clone = $(this).clone()
$(this).after(clone);
$(this).css( {
'font-size' : '2em',
'background-color' : '#fff',
'position' : 'absolute'
})
}, function() {
clone.remove();
$(this).css( {
'font-size' : '1em',
'position' : 'inherit'
})
});
Check the running example at http://jsfiddle/39YKG/
As soon as the mouseover for that word is fired create a new element in the DOM (without effecting the current word element) and have it absolutely position on the page exactly where the word element is (thanks to jQuery's .position()
).
With some padding you can make it align perfectly to the word.
Don't forget to remove it on mouseout.
If you don't object to a pure CSS solution, with its somewhat imperfect cross-browser patibility you can use :hover:after
and content: attr(title);
to achieve this:
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
}
);
</script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode./svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
p span.special {
display: inline;
position: relative;
color: #f90;
}
p span.special:hover:after {
position: absolute;
top: 0;
left: 0;
font-size: 3em;
padding: 0.2em;
border: 1px solid #ccc;
background-color: #fff;
content: attr(title);
}
</style>
</head>
<body>
<p>Est diam cras diam ultrices sagittis. Purus platea in nascetur nunc ac. In lacus massa. Sit pulvinar egestas amet magnis, nec! Ac pulvinar ac magna? Odio hac <span class="special" title="facilisis">facilisis</span>, in massa. Nascetur lacus lacus aliquet! Quis? Augue? Ultrices sit porttitor pulvinar a rhoncus, etiam, mauris phasellus lorem augue ac. Facilisis pulvinar integer urna, egestas magna, odio, nisi, vut odio magna integer.</p>
</body>
</html>
Demo at JSBin.
$('span#yourId').mouseover(function(){
$(this).css('font-size', '30px');
});
Assuming 30px is the max size you want.
本文标签: javascriptincrease size of text on mouse hover cssjqueryhtmlStack Overflow
版权声明:本文标题:javascript - increase size of text on mouse hover cssjqueryhtml - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742339444a2456298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论