Jquery slips up and down, what should I do?

im not familiar with jquery so any help would be appreciated, i have some code, (cant remember where from) that shows part of the content and then allows you to show more or less.

What i would like the code to do is exactly what it does now, but instead of just show / hide, i want it to slide down and up revealing more or less content.

THE WHOLE CODE



Show more less


#mytext {width:260px;height:200px;overflow:hidden;}



$(document).ready(function() {
var adjustheight = 200;
$("#adjust").toggle(function() {
$('#mytext').css('height', 'auto').css('overflow', 'visible');
$(this).text("less");
}, function() {
$('#mytext').css('height', adjustheight).css('overflow', 'hidden');
$(this).text("more");
});
});






Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque iaculis tincidunt tortor. Nulla turpis dui, gravida non, varius quis, molestie sit amet, justo. Vestibulum sed elit. Duis lobortis odio quis nisi. Praesent enim. Sed auctor commodo lectus. In eget augue a nulla auctor interdum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla enim turpis, commodo at, feugiat nec, dapibus et, odio. Cras enim risus, sagittis eget, ultrices quis, eleifend vel, risus. Cras a felis eu urna ornare vulputate. Pellentesque viverra, lacus vitae tincidunt accumsan, nisi metus feugiat felis, sed placerat est dolor et eros. Duis cursus. Maecenas sollicitudin, lorem vitae placerat eleifend, dui elit imperdiet tellus, at convallis sapien orci sed pede.
more

its currently controlled by changing the height in the css any way to animate this? Thanks

Have you taken a look at the slideToggle
method?

// Open & Close myDiv.  Animation take 1 second (1000 ms)
$('#myDiv').slideToggle(1000);

Edit: Here’s a better answer.

In your HTML, have a div for the stuff you always want to see, and another div for the things that are hidden.

Here is an introduction to what I want to say.
More...
Here is some more info that you don't always care about

This way you can toggle just sometimesShow
. Its not exactly what you asked for, but I think it will solve your problem.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Jquery slips up and down, what should I do?

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录