Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 滑块切换在JSFIDLE中工作,但不是活动的_Javascript_Jquery_Slider_Slidetoggle_Jsfiddle - Fatal编程技术网

Javascript 滑块切换在JSFIDLE中工作,但不是活动的

Javascript 滑块切换在JSFIDLE中工作,但不是活动的,javascript,jquery,slider,slidetoggle,jsfiddle,Javascript,Jquery,Slider,Slidetoggle,Jsfiddle,正如标题所述,我制作了一个滑块,可以在JSFIDLE预览中使用,但不是实时的 以下是小提琴的链接: 以下是我在网站上发布的javascript: $(document).ready(function() { var $div1 = $('#work'), $div2 = $('#play'), currentDiv = 'play', $button = $('button'); $div2.hide(); $button.text('Recent ' + curre

正如标题所述,我制作了一个滑块,可以在JSFIDLE预览中使用,但不是实时的

以下是小提琴的链接:

以下是我在网站上发布的javascript:

$(document).ready(function() {

var $div1 = $('#work'),
    $div2 = $('#play'),
    currentDiv = 'play',
    $button = $('button');

$div2.hide();
$button.text('Recent ' + currentDiv);

$(document).on('click', 'button', function (evt) {
    $div1.toggle('fade', 'fast');
    $div2.toggle('fade', 'fast');

    currentDiv = (currentDiv === 'play') ? 'work' : 'play';
    $button.text('Recent ' + currentDiv);
});
});
这是HTML

<div class="SlideContain">
        <div id="work">
            <div id="desc">Description of work here</div>
            <div id="image">image of work here</div>
        </div>
        <div id="play">
            <div id="desc">Description of work here</div>
            <div id="image">image of work here</div>
        </div>
        <div class="clear"></div>
    </div><br />
    <button>Toggle</button>

这里的工作描述
这里的工作形象
这里的工作描述
这里的工作形象

切换

它会突然切换一次,然后按钮切换,但不会触发动画。我遗漏了什么?

您可能遗漏了jQuery UI 1.9.2库


我在您的演示中排除了
jqueryui
库,它开始像您描述的那样工作:

复制了OP的小提琴示例,如下所示,它对我有效

我只是修改了一下

  <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script> 


Slider-JSFIDLE演示套件87
#第一组{
宽度:100%;
高度:100px;
背景色:#333333;
位置:绝对位置;
顶部:0px;
左:0px;
}
#第二组{
宽度:100%;
高度:100px;
背景色:红色;
位置:绝对位置;
顶部:0px;
左:0px;
}
#描述{
宽度:50%;
高度:自动;
浮动:左;
填充:0;
背景色:#666666;
位置:相对位置;
左:0px;
顶部:0px;
}
#形象{
宽度:50%;
高度:自动;
浮动:对;
填充:0px;
背景色:#655555;
}
.清楚{
明确:两者皆有;
}
.集装箱{
宽度:100%;
位置:相对位置;
左:0px;
高度:100px;
}
@媒体屏幕和屏幕(最大宽度:360px){
#描述{
宽度:100%;
高度:50px;
}
#形象{
宽度:100%;
高度:50px;
}
}
//  
标题在这里

这里的工作描述 这里的工作形象
切换
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script> 


<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Slider - jsFiddle demo by kits87</title>

  <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script> 
  <script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">

  <link rel="stylesheet" type="text/css" href="/css/result-light.css">

  <style type='text/css'>
    #div1 {
    width: 100%;
    height: 100px;
    background-color:#333333;
    position: absolute;
    top: 0px;
    left: 0px;
}
#div2 {
    width: 100%;
    height: 100px;
    background-color: red;
    position: absolute;
    top: 0px;
    left: 0px;
}
#desc {
    width:50%;
    height:auto;
    float:left;
    padding:0;
    background-color:#666666;
    position:relative;
    left:0px;
    top:0px;
}
#image {
    width:50%;
    height:auto;
    float:right;
    padding:0px;
    background-color:#655555;
}
.clear {
    clear: both;
}
.container {
    width: 100%;
    position: relative;
    left: 0px;
    height: 100px;
}
@media screen and (max-width:360px) {
    #desc {
        width:100%;
        height:50px;
    }
    #image {
        width:100%;
        height:50px;
    }
}
  </style>



<script type='text/javascript'>//<![CDATA[ 
$(function(){
var $div1 = $('#div1'),
    $div2 = $('#div2'),
    currentDiv = 'play',
    $button = $('button');

$div2.hide();
$button.text('Recent ' + currentDiv);

$(document).on('click', 'button', function (evt) {
    $div1.toggle('fade', 'fast');
    $div2.toggle('fade', 'fast');

    currentDiv = (currentDiv === 'play') ? 'work' : 'play';
    $button.text('Recent ' + currentDiv);
});
});//]]>  

</script>


</head>
<body>
  <body>
    <p>Header here</p>
    <div class="container">
        <div id="div1">
            <div id="desc">Description of work here</div>
            <div id="image">image of work here</div>
        </div>
        <div id="div2"></div>
        <div class="clear"></div>
    </div><br />
    <button>Toggle</button>
</body>

</body>


</html>