我需要无限的onclick和transitions'不起作用
I need infinite onclick and transitions doesn't work
我正在尝试制作一个照片库,但我有两个问题。。。
-
在我的javascript"onclick"中,我只能点击1次,我需要能够点击任意次数的
-
我的转换不起作用,正如你所看到的,它在没有转换的情况下立即"移动"照片,但我需要这种转换,否则会很难看。
Fiddle:http://jsfiddle.net/0Lg891p0/
<!DOCTYPE html>
<html lang="cs-CZ">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Rostislav_Danko">
<link rel="stylesheet" href="Web.css">
<title>Rostislav Danko</title>
</head>
<body>
<div id="web">
<div id="galerie">
<div id="fotky">
<img id="fotka1" src="fotka1.jpg" alt="fotka1" />
<img id="fotka2" src="fotka2.jpg" alt="fotka2" />
<img id="fotka3" src="fotka3.jpg" alt="fotka3" />
</div>
<div id="arrow_left" class="animace1"></div>
<div id="arrow_right" class="animace2"></div>
<script>
document.querySelector('.animace1').onclick=function() {
var d = document.getElementById("fotka1");
d.className = d.className + " fly1";
var t = document.getElementById("fotka2");
t.className = t.className + " fly1";
var t = document.getElementById("fotka3");
t.className = t.className + " fly1";
}
</script>
<script>
document.querySelector('.animace2').onclick=function() {
var d = document.getElementById("fotka1");
d.className = d.className + " fly2";
var t = document.getElementById("fotka2");
t.className = t.className + " fly2";
var t = document.getElementById("fotka3");
t.className = t.className + " fly2";
}
</script>
</div>
</div>
</body>
</html>
CSS
#web {
background-color: #FF0;
height: 700px;
width: 1500px;
}
#galerie {
}
#fotky {
}
#fotka1 {
position: absolute;
height: 300px;
width: 300px;
margin-top: 300px;
margin-left: 500px;
border: solid 10px;
z-index: 1;
display: block;
transition: ease-in-out 1s;
}
#fotka1.fly1 {
position: absolute;
left: 300px;
top: 8px;
transition: ease-in-out 1s;
}
#fotka1.fly2 {
position: absolute;
left: -300px;
top: 8px;
transition: ease-in-out 1s;
}
#fotka2 {
position: absolute;
height: 300px;
width: 300px;
margin-top: 300px;
margin-left: 200px;
border: solid 10px;
z-index: 1;
display: block;
transition: ease-in-out 1s;
}
#fotka2.fly1 {
position: absolute;
left: 300px;
top: 8px;
transition: ease-in-out 1s;
}
#fotka2.fly2 {
position: absolute;
left: -300px;
top: 8px;
transition: ease-in-out 1s;
}
#fotka3 {
position: absolute;
height: 300px;
width: 300px;
margin-top: 300px;
margin-left: 800px;
border: solid 10px;
z-index: 1;
display: block;
transition: ease-in-out 1s;
}
#fotka3.fly1 {
position: absolute;
left: 300px;
top: 8px;
transition: ease-in-out 1s;
}
#fotka3.fly2 {
position: absolute;
left: -300px;
top: 8px;
transition: ease-in-out 1s;
}
#arrow_left {
width: 50px;
height: 50px;
background-color: #F00;
margin-top: 450px;
margin-left: 470px;
position: absolute;
z-index: 10;
}
#arrow_right {
width: 50px;
height: 50px;
background-color: #F00;
margin-top: 450px;
margin-left: 800px;
position: absolute;
z-index: 10;
}
您的问题之一是不断向元素中添加类,而从不删除旧类,这就是为什么您的单击只起作用一次的原因。在设置新类之前,您需要清除旧类:
<script>
document.querySelector('.animace1').onclick = function () {
document.getElementById("fotka1").className = "fly1";
document.getElementById("fotka2").className = "fly1";
document.getElementById("fotka3").className = "fly1";
};
document.querySelector('.animace2').onclick = function () {
document.getElementById("fotka1").className = "fly2";
document.getElementById("fotka2").className = "fly2";
document.getElementById("fotka3").className = "fly2";
};
</script>
另一个最初的"突然跳跃"问题是,你有冲突的CSS内容,你可以简化为这样说:
#fotka1 {
position: absolute;
height: 300px;
width: 300px;
margin-top: 300px;
margin-left: 500px;
border: solid 10px;
z-index: 1;
display: block;
top: 8px;
left: 0px;
transition: ease-in-out 1s;
}
#fotka1.fly1 {
left: 300px;
}
#fotka1.fly2 {
left: -300px;
}
请参阅jsfiddle:http://jsfiddle.net/0Lg891p0/1/
相关文章:
- Jquery:输入类型=“”;按钮“;使用.click()函数在Internet Explorer和Safari中不起作
- 如何选择数组中的第一个对象(当 array[0] 不起作用时)
- document.getElementById('myControl').focus() 在 PhoneGap 中不起作
- JQuery prop('required', false, (!$(this).is(':checked')) 不起作
- 为什么从 JavaScript 调用 Flash 函数可以工作,但 FileReference 在 Flash 中不起作
- 捆绑和缩小 - 启用脚本不起作用时
- fb:like 当被要求登录 IE 不起作用时
- document.head.appendChild 或 document.createElement 在 IE 中不起作
- 我需要无限的onclick和transitions'不起作用
- 主页链接'的背景颜色在Internet explorer中发生了变化,但在Mozilla Firefox中不起作
- HTML、PHP、JavaScript——如何为数据库中的每个单独记录制作一个按钮?看起来很简单,但事实并非如此;不起作
- 当页面请求和重载javascript函数不起作用时
- 在使XMLHttpRequest到服务器头(“location:index.php”)函数不起作用时
- 当getElementById不起作用时,如何查找输入字段的id
- 当fontWeight不起作用时,如何使HTML5字体更轻?
- 当$.ajax()不起作用时,并行调用$
- 使用helper: 'original'With sortable()和draggable()似乎不起作
- 当等价的if语句起作用时,switch语句不起作用
- element2.focus() 在 element1.onblur() 在 Fx/Chrome/Safari 中不起作
- 当 window.location=self.location 不起作用时,通过 AJAX 重新加载页面