javascript - Div 幻灯片 (html, css, js)

标签 javascript html css

我开始了创建网页的旅程。我渴望尝试模仿 Windows 10 启动 UI 以及浏览器上的动画。但问题是我还不了解 javascript。如果您不介意,请检查我的代码是否存在一些问题。谢谢。

HTML

<!DOCTYPE html>
<html>
<head>
    <title>WinCalc</title>
    <link rel="stylesheet" type="text/css" href="index.css">
    <script type="text/javascript" src="index.js"></script>
</head>
<body onload="slideShow()">
    <form method="POST" action="" autocomplete="off">
        <div id="holder">
            <div id="wrapper">
                <div id="savButtondesc">
                    <div id="savDesc"> Sum, Average & Max</div>
                    <div id="savDesc1"> Display Sum, Average & Max of the number inputted.</div>
                </div>
                <input id="savButton" type="button" name="sav">


            </div>
        </div>
    </form>
</body>
</html>

CSS

 @font-face {
    font-family: RobotoL;
    src:url(fonts/Roboto-Light.ttf);
}

body {
    overflow: hidden;
}
#holder {
    width: 50%;
    height: 100%;
    margin-left: 25%;
    margin-right: 25%;
    position: absolute;
    background-color: #34495e;
}
#wrapper {
    background-color: white;
    position: absolute;
    margin-top: 24%;
    margin-bottom: 25%;
    margin-right: 25%;
    margin-left: 25%;
    width: 50%;
    height: 50%;
}
#savButton {
    border-style: none;
    background-color: #3498db;
    position: relative;
    opacity: .1;
    height: 50%;
    width: 100%;
}
#savButtondesc {
    background-color: red;
    width: 100%;
    height: 50%;
    position: absolute;
}
#savDesc {
    width: 100;
    margin-top: 17%;
    margin-bottom: 20%;
    margin-right: 10%;
    margin-left: 10%;
    font-family: RobotoL;
    font-size: 30px;
    color: white;
    transition: 1s;
}
#savDesc1 {
    font-family: RobotoL;
    font-size: 15px;
    color: white;
    margin-left: 1%;
    margin-top: -50%;
    transition: 1s;
    opacity: 0;

}

JavaScript

    function slideShow() {
    setInterval( function show(){
        var next = 0;
        if (next == 0) {
            animate();
            next++:
        }
        else {
            reverse();
            next--;
        }
    },1000);

}
function animate(){
        document.getElementById('samDesc').style.marginTop = "-2%";
        document.getElementById('samDesc1').style.marginTop = "25%";
        document.getElementById('samDesc1').style.opacity = "1";
        document.getElementById('samDesc').style.opacity = "0";
}
function reverse(){
        document.getElementById('samDesc').style.marginTop = "17%";
        document.getElementById('samvDesc1').style.marginTop = "-55%";
        document.getElementById('samDesc1').style.opacity = "0";
        document.getElementById('samDesc').style.opacity = "1";
}

最佳答案

使用slideShow();在您的 JavaScript 代码的末尾。

无论如何,我推荐你使用http://unslider.com/作为 jQuery 插件。

关于javascript - Div 幻灯片 (html, css, js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38547361/

相关文章:

javascript - 如何转换来自 http.post 响应 json 的数据以便我可以在我的应用程序中使用它?

html - knitr、R Markdown 和 xtable : xtable tables within HTML table

css - youtube等嵌入元素的2D变换

html - 帮助使用 CSS 选择器(jQuery 日期选择器)

html - 使用纯 css 延迟 css 位置更改

javascript - 如何通过单个处理函数处理来自各种按钮的 DOM 事件

javascript - 替换 eval 以获取表单 javascript 中的值

javascript - Google Chrome 语音转文本 API JavaScript 连续不起作用?

html - JTable getInstance 不工作

javascript - 慢慢打印文本,并解释 html