php简单特效_一个简单的小动画效果

演示效果:

af134b72c2072a127711a21cc841d424.gif

项目需要做这个效果,把效果写出来了顺便就封装成了一个插件,也练习了一下插件的写法。

代码:

html:这个没什么说的,就是简单的布局:在图片上有一个介绍,介绍定位在区域外部。

  • animation1.jpg
    点我吧
  • animation2.jpg
    点我吧
  • animation3.jpg
    点我吧
  • animation4.jpg
    点我吧

JS插件效果:把效果封装成了一个插件,以后直接调用就行了。

//移入移出插件(function($) {

$.fn.extend({"lonelyMove": function(options) {var defaults = {

time: .3,

close: null}var opts = $.extend(true, defaults, options);var vision = /mobile/.test(navigator.userAgent.toLowerCase());return $(this).on('mouseenter mouseleave', function(event) {if(!vision) {var event = event || window.event,

liWidth = $(this).width(),

liHeight = $(this).height(),

u0 = (event.pageX - ($(this).offset().left) - (liWidth / 2)) * (liWidth > liHeight ? (liHeight / liWidth) : 1),

F0 = (event.pageY - ($(this).offset().top) - (liHeight / 2)) * (liHeight > liWidth ? (liWidth / liHeight) : 1),

index = Math.round((((Math.atan2(F0, u0) * (180 / Math.PI)) + 180) / 90) + 3) % 4,

location = [{'top': "-100%",'left': '0%'}, {'top': '0%','left': "100%"}, {'top': "100%",'left': '0%'}, {'top': '0%','left': "-100%"}],

type = event.type;if(type == 'mouseenter') {

$(this).find(opts.moveClass).css(location[index]);

TweenMax.to($(this).find(opts.moveClass), opts.time, {

css: {

top: 0,

left: 0},

ease: Cubic.Linear

});

} else {

TweenMax.to($(this).find(opts.moveClass), opts.time, {

css: location[index],

ease: Cubic.Linear

});

}

}

});

}

});

})(jQuery);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我是一个语言模型,无法为您提供完整的代码,但我可以为您提供一些相关的参考资料。 幻灯片特效和其他特效动画效果可以通过使用JavaScript库和框架来实现。以下是一些常用的库和框架: 1. jQuery:一款非常流行的JavaScript库,可以轻松地实现各种特效动画效果。 2. Bootstrap:一款流行的CSS框架,提供了许多便捷的组件和样式,包括幻灯片和其他特效。 3. Animate.css:一个轻量级的CSS动画库,可以为网页添加各种动画效果。 4. WOW.js:一个JavaScript库,可以在滚动时触发各种动画效果。 下面是一个简单的示例代码,使用jQuery和Bootstrap实现一个简单的幻灯片特效: ```html <!DOCTYPE html> <html> <head> <title>Slide Show</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <style> .carousel-inner img { width: 100%; height: 500px; } </style> </head> <body> <div class="container"> <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner"> <div class="item active"> <img src="img1.jpg" alt="Image 1"> </div> <div class="item"> <img src="img2.jpg" alt="Image 2"> </div> <div class="item"> <img src="img3.jpg" alt="Image 3"> </div> </div> <!-- Left and right controls --> <a class="left carousel-control" href="#myCarousel" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> <span class="sr-only">Previous</span> </a> <a class="right carousel-control" href="#myCarousel" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> <span class="sr-only">Next</span> </a> </div> </div> <script> $(document).ready(function(){ // Activate Carousel $("#myCarousel").carousel(); }); </script> </body> </html> ``` 注意,这只是一个简单的示例代码,您可以根据需要进行修改和扩展。同时,还可以结合其他库和框架,添加更多的特效动画效果

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值