简体   繁体   English

如何创建一个使用4个图像来导航而不是文本的JQuery内容滑块?

[英]How do I create a JQuery content slider that uses 4 images to navigate rather than text?

I have for images with a number on it. 我有图片上有数字。 Those numbers are 1-4. 这些数字是1-4。 I want to place them numerically and when the user clicks on 1, i want them to go to slide 1 and if they click on 2, then slide 2. This also needs to have a sliding effect. 我想以数字方式放置它们,当用户点击1时,我希望它们转到幻灯片1,如果它们单击2,则滑动2.这也需要具有滑动效果。

I am using this particular javascript code below for left and right options but i am not sure if I can re-use this for my purpose: 我在下面使用这个特定的javascript代码左右选项,但我不确定我是否可以为我的目的重新使用它:

HTML would be something like: HTML将类似于:

<img src="#" class="image_one">
<img src="#" class="image_two">
<img src="#" class="image_three">
<img src="#" class="image_four">

<div class="content_for_image_One" id="slide1">
You see this when you click on image 1
</div>

<div class="content_for_image_two" id="slide2">
You see this when you click on image 2
</div>

<div class="content_for_image_three" id="slide3">
You see this when you click on image 3
</div>

<div class="content_for_image_four" id="slide4">
You see this when you click on image 4
</div>

<script type="text/javascript">
            $(document).ready(function () {

                var $sliderMask = $('#slider_mask');
                var $slideContainer = $('#slide_container');

                var $slides = $slideContainer.find('.slide');

                var slideCount = $slides.length;
                var slideWidth = $sliderMask.width();

                $slideContainer.width(slideCount * slideWidth);
                $slides.width(slideWidth);

                var currentSlide = 0;

                function animate() {
                    $slideContainer.stop().animate({ marginLeft: -(currentSlide * slideWidth) + 'px' }, 'slow');
                }

                $('#left_button').on('click', function () {
                    currentSlide = (currentSlide - 1 + slideCount) % slideCount;
                    animate();
                });

                $('#right_button').on('click', function () {
                    currentSlide = (currentSlide + 1) % slideCount;
                    animate();
                });

                $('#click_left').on('click', function () {
                    currentSlide = (currentSlide - 1 + slideCount) % slideCount;
                    animate();
                });

                $('#click_right').on('click', function () {
                    currentSlide = (currentSlide + 1) % slideCount;
                    animate();
                });


            });

</script>

Your provided html does not fit to your code, but let's assume you have the following html: 您提供的html不适合您的代码,但我们假设您拥有以下html:

<div id="slidesWrapper">

    <div id="slidesContainer">

        <div class="slide"><!-- your html --></div>
        <div class="slide"><!-- your html --></div>
        <div class="slide"><!-- your html --></div>
        <div class="slide"><!-- your html --></div>

    </div>

</div>

<div id="thumbnails">
    <img src="#" class="thumb" />
    <img src="#" class="thumb" />
    <img src="#" class="thumb" />
    <img src="#" class="thumb" />
</div>

with the following css: 使用以下css:

#slidesWrapper {
    width: 1000px;
    height: 400px;
    overflow: hidden;
    position: relative;
}

#slidesContainer {
    width: auto;
    position: aboslute;
}

.slide {
    float: left;
    height: 400px;
}

you could use something like: 你可以使用类似的东西:

(function($){
    $(function() {
        var wrapper = $('#slidesWrapper'),
            container = $('#slidesContainer'),
            slides = container.children(),
            thumbs = $('#thumbnails').children();

        container.css('left', '0');

        thumbs.click(function() {
            var index = $('thumbnails').children().index(this);

            container.stop().animate({
                left: '-' + slides.eq(index).position().left + 'px'
            }, 1000);
        });
    });
})(jQuery);

its not tested though and I dont quite get what you want. 它没有经过测试,我也没有得到你想要的东西。 This example fits if you have a wrapper with slides in it and only one can be visible, fixed width and height 如果您有一个带有幻灯片的包装器,并且只有一个可见,固定宽度和高度,则此示例适合

function next()
{
var mar=$("#img_ul").css("margin-left");
var nm=mar.replace("px","");
if(nm==0)
{
  $("ul").animate({"marginLeft":"-500px"},"slow");
}
else if(nm>0 || nm!=-2000)
{
  nm=nm-500;
  $("ul").animate({"marginLeft":nm+"px"},"slow");
}
else if(nm==-2000)
{
  $("ul").animate({"marginLeft":"0px"},"slow");
}
}

function previous()
{
var mar=$("#img_ul").css("margin-left");
var nm=mar.replace("px","");
if(nm==0)
{
  $("ul").animate({"marginLeft":"-2000px"},"slow");
}
else
{
  nm=+nm + +500;
  $("ul").animate({"marginLeft":nm+"px"},"slow");
}
}
</script>
</head>

<body>

 <div id="slide_wrapper">
 <ul id="img_ul">

 <li>
  <q>
    Learn everything you can, anytime you can, from anyone you can there will always come a time when you will be grateful 
    you did.
  </q>
 </li>

 <li>
  <q>
    Make it simple. Make it memorable. Make it inviting to look at. Make it fun to read.
  </q>
 </li>

 <li>
  <q>
    If plan A fails, remember there are 25 more letters.
  </q>
 </li>

 <li>
  <q>
    Do not go where the path may lead, go instead where there is no path and leave a trail.
  </q>
 </li>

 <li>
  <q>
    A journey of a thousand miles must begin with a single step.
  </q>
 </li>


 </ul>
 </div>

 <input type="button" id="previous" value="Previous" onclick="previous();">
 <input type="button" id="next" value="Next" onclick="next();">

code from TalkersCode complete tutorial here http://talkerscode.com/webtricks/content-slider-using-jquery-and-css.php 来自TalkersCode的代码完整教程http://talkerscode.com/webtricks/content-slider-using-jquery-and-css.php

暂无
暂无

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

相关问题 如何使此滑块自动播放图像而不是单击 - how to make this slider autoplay the images rather than click 如何获取第一个元素而不是在 jQuery 中使用 [0]? - How do I get first element rather than using [0] in jQuery? 如何创建一个可以更改主页内容以及滑块内容并为过渡设置动画效果的滑块? - How do I create a slider that changes the main page content as well as the slider content and animates the transitions? 如何从数据库中的图像创建jQuery滑块? - How to create jQuery slider from images in a Database? 我在 JQuery 代码上将什么更改为单击文本而不是在悬停时更改? - What do I change on JQuery Code to Click Text rather than change on Hover? 切换此元素而不是文本时,如何显示不同的图像 - How can I make different images display when this element is toggled, rather than text 如何为内联元素创建垂直jQuery或CSS滑块 - How do I create a vertical jQuery or CSS slider for an inline element jQuery的/ JavaScript的:如何顺序(而不是并行)加载(一些)图像? - jquery/javascript: how to load (some) images sequentially rather than in parallel? 使用ng-clip,如何将内容添加到剪贴板表单代码(而不是以声明方式在标记中)? - Using ng-clip, how do I add content to the clipboard form code (rather than declaratively in markup)? 使用jQuery,我如何Ajax将文本加载到多个.class中而不是#id中? - Using jQuery, how can I ajax load text into multiple .classes rather than #id's?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM