我正在为我的Joomla寻找滑动切换jQuery!网站,将在this example工作:我希望我的文章从一个句子的开始,然后(阅读更多)开始。点击(阅读更多)将隐藏(阅读更多)并显示句子的结尾(没有换行符,甚至空格)。在完整句子结尾处,有一个“关闭”的链接。jquery滑动切换没有换行符
对于我的尝试,我使用了一个技巧来解决问题,但它不工作(当我点击“开始的句子”而不是“(...)”toogle隐藏所有的内容我的Joomla文章(即便如此,它的工作here)
HTML:
<ul id="containertoggle">
<li><a class="opener" style="text-decoration: none;"> <span style="color: #585858;">This is the begining of the sentence </span>(...)</a>
<div style="display: none;">
<p>This is the beginning of the sentence and this is the end of the sentence </p>
</div></li>
<li><a class="opener" style="text-decoration: none;"> <span style="color: #585858;">This is the begining of the sentence </span>(...)</a>
<div style="display: none;">
<p>This is the beginning of the sentence and this is the end of the sentence </p>
</div></li></ul>
QUERY
var $j = jQuery.noConflict();
$j(function() {
$j('#containertoggle').on('click', 'a.opener', function() {
$j(this).next().toggle('slow').find('p').append('<span>[close]</span>');
$j(this).hide();
});
$j('#containertoggle').on('click', 'span', function() {
$j(this).closest('div').toggle('slow').closest('li').find('a').show();
$j(this).remove();
});
});
感谢您的帮助史蒂夫!是的,这非常有帮助!我试过你的代码,它的工作正常,但我试图解决你的代码来获取代码,让我显示不同长度的“句首”(如替换var showChar = 100;通过“阅读更多”句子),但没有成功。当“句尾”出现时,我也试图添加一种缓慢的切换效果,但它也没有成功! – JinSnow
你可以查看这个http://jsfiddle.net/nZyXJ/1/ – steve
我很抱歉,我读了我的评论,而且根本不清楚。 var showChar = 100不能用于我的情况,因为我有时需要在100个字符之后开始我的切换,但有时候它会是300.事实上,我甚至不知道字符的数量,因为我将开始切换在句子中最好的地方,所以它可以在3个单词之后或50个单词之后。我无法预测切换的位置,所以jquery必须反映这种灵活性。再次,我很抱歉,我的坏。 – JinSnow