【发布时间】:2013-07-12 17:08:20
【问题描述】:
首先让我说我是 JQuery 的新手,所以我猜测我的方式,这并不理想,但我将投入更多时间正确学习。
代码:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.core.js"></script>
<script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/jquery.effects.slide.js"></script>
<script type="text/javascript">
jQuery.fn.extend({
slideRightShow: function(speed) {
return this.each(function() {
$(this).show('slide', {direction: 'right'}, +speed || 1000);
});
},
slideLeftHide: function(speed) {
return this.each(function() {
$(this).hide('slide', {direction: 'left'}, +speed || 1000);
});
},
slideRightHide: function(speed) {
return this.each(function() {
$(this).hide('slide', {direction: 'right'}, +speed || 1000);
});
},
slideLeftShow: function(speed) {
return this.each(function() {
$(this).show('slide', {direction: 'left'}, +speed || 1000);
});
}
});
$(document).ready(function () {
$(".left_hand_icon").on("click", function () {
$("#slide1").slideLeftShow();
});
});
$(document).ready(function () {
$(".right_hand_icon").on("click", function () {
$("#slide2").slideRightShow();
});
});
</script>
HTML:
<div class="navigator">
<div class="left_hand_icon">Left</div>
<div class="right_hand_icon">Right</div>
</div>
<div id="slide1">Slide 1 content</div> <!-- displayed by default and i need to slide this away when the next slide is requested -->
<div id="slide2" style="display:none">Slide 2 content</div>
<div id="slide3" style="display:none">Slide 3 content</div>
<div id="slide4" style="display:none">Slide 4 content</div>
我需要什么帮助?
使用我的 JS:
1) 我如何在单击 left_hand_icon 或 right_hand_icon 时使当前内容滑开然后显示下一个内容?我正在使用显示:无;隐藏它们,但是当它显示时我如何隐藏当前的。你能帮我找到正确的方向吗?
2) 加载页面时,会显示第一张幻灯片。由于我们在第一张幻灯片上,如何禁用用户单击左侧的功能显示?
你能帮我找到正确的方向吗?
【问题讨论】:
-
顺便说一句,您的 HTML 中的第 4 行有错字(right_hand_icon div 未关闭,您在
</div>中缺少/。 -
@emillundberg 感谢您的关注。我在问题和脚本中进行了更改。
标签: javascript jquery slider slideshow