Javascript slide effect onclick(Javascript 幻灯片效果 onclick)
问题描述
我想添加一张幻灯片 &使用onclick"使用纯 Javascript 对 DIV 进行淡入淡出效果.
I'd like to add a slide & fade effect to a DIV, with purely Javascript, using "onclick".
代码在这里:http://jsfiddle.net/TCUd5/
必须滑动的 DIV 具有 id="pulldown_contents_wrapper".此 DIV 包含在 SPAN 中,它也会触发它:
The DIV that has to slide has id="pulldown_contents_wrapper". This DIV is contained in a SPAN, that also triggers it:
<span onclick="toggleUpdatesPulldown(event, this, '4');" style="display: inline-block;" class="updates_pulldown" >
<div class="pulldown_contents_wrapper" id="pulldown_contents_wrapper">
而且我认为控制 SPAN onclick 的 JS 代码是:
And I think the JS code that controls the SPAN onclick is:
var toggleUpdatesPulldown = function(event, element, user_id) {
if( element.className=='updates_pulldown' ) {
element.className= 'updates_pulldown_active';
showNotifications();
} else {
element.className='updates_pulldown';
}
}
如果不能用纯 JS 来实现,你知道我怎么能用 Mootools 来实现吗?(*我只想使用纯 JS 或 Mootols 框架).
If it is not possible to make it with pure JS, do you have an idea how could I do it with Mootools? (*I'd like to use only pure JS or the Mootols framework).
我尝试实现以下代码:为什么 javascript onclick div slide not工作?但没有结果.
I have tried to implement the code from: why javascript onclick div slide not working? but with no results.
非常感谢.
我已经设法使用 Mootools 制作了它,但我不知道如何添加幻灯片 &淡入淡出效果和鼠标移出延迟
I have managed to make it with Mootools, but I can't figure it out how to add a slide & fade effect, and a delay on mouseout
window.addEvent('domready', function() {
$('updates_pulldown').addEvents({
mouseenter: function(){
$('updates_pulldown').removeClass('updates_pulldown').addClass('updates_pulldown_active')
$('pulldown_contents_wrapper').set('tween', {
duration: 1000,
physics: 'pow:in:out',
transition: Fx.Transitions.Bounce.easeOut // This could have been also 'bounce:out'
}).show();
},
mouseleave: function(){
$('pulldown_contents_wrapper').set('tween', {
duration: 1000,
delay: 1000,
}).hide();
$('updates_pulldown').removeClass('updates_pulldown_active').addClass('updates_pulldown')
},
});
});
var toggleUpdatesPulldown = function(event, element, user_id) {
showNotifications();
}
有什么想法吗?
推荐答案
jQuery 简单很多,但是纯javascript你可以做到.
jQuery is a lot easier, but with pure javascript you can do it.
在 CSS 中你需要使用过渡
In the CSS you'll need to use transitions
#thing { position:relative;
top: 0px;
opacity: 0.8;
-moz-transition: top 1s linear, opacity 1s linear;
-webkit-transition: top 1s linear, opacity 1s linear;
}
然后在javascript中当你改变元素的位置时,它应该通过css转换来改变.
then in the javascript when you change the position of the element, it should change via the css transitions.
var toggleUpdatesPulldown = function(event, element, user_id) {
if( element.className=='updates_pulldown' ) {
element.style.top = someValue; //something like '100px' will slide it down 100px
element.style.opacity = '1.0'; //will fade the content in from 0.8 opacity to 1.0
element.className= 'updates_pulldown_active';
showNotifications();
编辑 - 提供 jQuery 代码
调用 jQuery 库,最容易从 google 托管完成
call the jQuery library, most easily done from the google hosting
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
制作悬停功能
$(document).ready(function() {
$('.updates_pulldown').hover( //first function is mouseon, second is mouseout
function() {
$(this).animate({top: '50px'}).animate({opacity: '1.0'});
},
function() { //delay 1000 milliseconds, animate both position and opacity
$(this).delay(1000).animate({top: '0px'}).animate({opacity: '0.5'});
}
)
})
函数计时将与您在 css 中使用转换标记设置的任何时间相同.再次使用this"而不是类名可确保效果仅发生在悬停的类的特定实例上.我不确定这个动画是否正是你所要求的,但如果我正确理解了这个问题,那么主要功能将为你工作.只需更改数字等以满足您的需求.
the function timing will be the same as whatever you set it to in the css with transition tags. using 'this' instead of the class name again makes sure that the effect only occurs on the specific instance of the class that is hovered over. im not sure if this animation is exactly what you were asking for, but if i understand the question correctly then the main functionality will work for you. just change the numbers and such to fit your needs.
这篇关于Javascript 幻灯片效果 onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Javascript 幻灯片效果 onclick
基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01