常见的筋斗云特效

提供一个筋斗云特效
在这里插入图片描述
移动时,背景变为筋斗云,鼠标离开回到起始位置,可以点击更改其实位置。
代码如下`

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .focus {
            position: relative;
            width: 721px;
            height: 455px;
            background-color: beige;
            margin: auto;
            overflow: hidden;
        }
        .focus ul li {
            list-style: none;
            float: left; 
        }
        .focus ul {
            padding: 0;
            width: 1400%;
            margin: 0;
            position: absolute;
            top: 0px;
            left: 0;
        }
        .arr1, .arr2 {
            display: none;
            position: absolute;
            text-decoration: none;
            margin-top: -24px;
            top: 50%;
            width: 24px;
            height: 40px;
            background: rgba(0, 0, 0, .3);
            text-align: center;
            line-height: 40px;
            color: #fff;
            font-family: 'icomoon';
            font-size: 18px;
            z-index: 99;

        }
        .arr2 {
            right: 0;
        }
        ol li {
            float: left;
            width: 8px;
            height: 8px;
            list-style: none;
            width: 6px;
            height: 6px;
            background-color: rgba(0, 0,0, .4);
            border: 2px solid rgba(0, 0,0, .3);
            border-radius: 50%;
            float: left;
            margin: 0 4px;
            cursor: pointer;
        }
        .current {
            background-color: #fff;      
        }
        ol {
            position: absolute;
            bottom: 5px;
            left: 50%;

        }
    </style>
</head>
<body>
    <div class="focus">
        <a href="javaScript:;" class="arr1"><</a>
        <a href="javaScript:;" class="arr2">></a>
        <ul>
            <li>
                <a href="#"><img src="../image/focus.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="../image/focus1.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="../image/focus2.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="../image/focus3.jpg" alt=""></a>
            </li>
        </ul>
        <ol></ol>
    </div>
    <script>
        // 轮播图用ul实现
        var arr1 = document.querySelector('.arr1');
        var arr2 = document.querySelector('.arr2');
        var focus1 = document.querySelector('.focus');
        var ul = focus1.querySelector('ul');
        var ol = focus1.querySelector('ol');
        var focuswidth = focus1.offsetWidth;
        var circle = 0;
        var circle1 = 4;
        function animate(obj, target, callback) {
             // console.log(callback);  callback = function() {}  调用的时候 callback()

            // 先清除以前的定时器,只保留当前的一个定时器执行
            clearInterval(obj.timer);
            obj.timer = setInterval(function() {
                // 步长值写到定时器的里面
                // 把我们步长值改为整数 不要出现小数的问题
                // var step = Math.ceil((target - obj.offsetLeft) / 10);
                var step = (target - obj.offsetLeft) / 10;
                step = step > 0 ? Math.ceil(step) : Math.floor(step);
                if (obj.offsetLeft == target) {
                    // 停止动画 本质是停止定时器
                    clearInterval(obj.timer);
                    // 回调函数写到定时器结束里面
                    // if (callback) {
                    //     // 调用函数
                    //     callback();
                    // }
                    callback && callback();
                }
        // 把每次加1 这个步长值改为一个慢慢变小的值  步长公式:(目标值 - 现在的位置) / 10
                obj.style.left = obj.offsetLeft + step + 'px';

            }, 15);
        }
        focus1.addEventListener('mouseenter', function() {
            arr1.style.display = 'block';
            arr2.style.display = 'block';
        })
        focus1.addEventListener('mouseleave', function() {
            arr1.style.display = 'none';
            arr2.style.display = 'none';
        })
        for(var i = 0; i < ul.children.length; i++) {
            var li = document.createElement('li');
            li.setAttribute('index', i)
            ol.appendChild(li);
            li.addEventListener('click', function() {
                for(var i = 0; i < ol.children.length; i++) {
                    ol.children[i].className = '';
                }
                this.className = 'current';
                var index = this.getAttribute('index');
                num = num1 = index;
                circle = circle1 = index;                
                animate(ul, -index * focuswidth);

            })
        }
        ol.children[0].className = 'current';
        var first = ul.children[0].cloneNode(true);
        ul.appendChild(first);
        var num = 0;
        arr2.addEventListener('click', function() {
            if(num == 4) {
                ul.style.left = 4 * focuswidth + 'px';
                num = 0;
            }
            num++;
            animate(ul, -num * focuswidth);
            circle++;
            if(circle == 4) {
                circle = 0;
            }
            for(var i = 0; i < ol.children.length; i++) {
                ol.children[i].className = '';
            }
            ol.children[circle].className = 'current';
        })
        var num1 = 4;
        arr1.addEventListener('click', function() {
            if(num1 == 0) {
                ul.style.left = 0;
                num1 = 4;
            }
            num1--;
            animate(ul, -num1 * focuswidth);
            circle1--;
            if(circle1 == -1) {
                circle1 = 3;
            }
            for(var i = 0; i < ol.children.length; i++) {
                ol.children[i].className = '';
            }
            ol.children[circle1].className = 'current';
        })
        var timer1 = setInterval(function() {
            arr2.click();
        }, 2000)
    </script>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于图像增强与特效,您可以使用 Python 中的第三方库,如 OpenCV 和 PIL,来实现。 以下是一个使用 OpenCV 实现图像增强和特效的示例代码: ```python import cv2 # 读取图片 img = cv2.imread('test.jpg') # 灰度化 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 边缘检测 edges = cv2.Canny(gray, 100, 200) # 高斯滤波 blur = cv2.GaussianBlur(img, (5, 5), 0) # 保存图片 cv2.imwrite('test_gray.jpg', gray) cv2.imwrite('test_edges.jpg', edges) cv2.imwrite('test_blur.jpg', blur) # 显示图片 cv2.imshow('gray', gray) cv2.imshow('edges', edges) cv2.imshow('blur', blur) cv2.waitKey(0) cv2.destroyAllWindows() ``` 此代码将加载名为 `test.jpg` 的图像,对其进行灰度化、边缘检测和高斯滤波处理,并将结果保存到新的图像文件中。最后,它会显示处理后的图像。您可以根据需要调整参数以获得更好的效果。 对于按钮部分,您可以使用 Python 的 GUI 库来创建一个简单的窗口,并在窗口中添加一个按钮。以下是一个使用 Tkinter 库创建窗口并添加按钮的示例代码: ```python import tkinter as tk def button_click(): print('Button clicked') root = tk.Tk() # 创建按钮 button = tk.Button(root, text='Click me!', command=button_click) button.pack() root.mainloop() ``` 此代码将创建一个名为 `root` 的主窗口,并在窗口中添加一个名为 `Click me!` 的按钮。当用户单击按钮时,`button_click` 函数将被调用。您可以根据需要调整按钮的样式和功能。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值