如何使这个codepen适用于多个页面?

时间:2017-03-29 22:52:39

标签: javascript html css button transition

我正在使用我在codepen上找到的所有按钮的页面过渡效果。它适用于我的联系人按钮,但当我尝试创建其他页面时它不起作用。因此,如果我尝试为我的"关于"创建一个页面。按钮它将无法工作,它将只使用我的联系页面中的相同页面。所以基本上我的问题是如何使用这个codepen在每个按钮上创建具有不同内容的多个按钮。

以下是codepen:https://codepen.io/fralec/pen/xZBKzO

这是我网站上的按钮



/* JS scripts are added see github repo for more 
https://github.com/fralec/ElegantJS */

$('#contact').elegant({
    clickNextToClose: true,
    newTab: true,
    github: {
        id: ''
    },
    twitter: {
        id: ''
    },
    mail: {
        id: ''
    },
    steam: {
        id: ''
    }
});

body {
  background-color: black;
  font-family: "Source Sans Pro", sans-serif;
  color: #ccc;
  z-index: -100;
  background-color:black;
}

#home {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 20%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#about {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 37%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#projects {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 54%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#contact {
    position: absolute;
    width: 16%;
    background-color: transparent;
    border: 2px solid #FFF;
    margin-top: 12%;
    margin-left: 71%;
    height: 3em;
    color: #FFF;
    font-size: 1em;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 4px;
    animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

#home:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

#about:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

#projects:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

#contact:hover {
    color: #1dd2e2;
    border: 3px solid #18bdef;
    font-weight: bold;
}

@keyframes grain {
  0%, 100% { transform:translate(0, 0) }
  10% { transform:translate(-5%, -10%) }
  20% { transform:translate(-15%, 5%) }
  30% { transform:translate(7%, -25%) }
  40% { transform:translate(-5%, 25%) }
  50% { transform:translate(-15%, 10%) }
  60% { transform:translate(15%, 0%) }
  70% { transform:translate(0%, 15%) }
  80% { transform:translate(3%, 35%) }
  90% { transform:translate(-10%, 10%) }
}

@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes fadein { /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <title>Home</title>
    
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro|Play" rel="stylesheet">
    
    <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css'>
    <link rel='stylesheet prefetch' href='http://rawgit.com/fralec/elegantShareJS/master/css/elegant.css'>

    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>  
<body>
    
    <button id="home">Home</button>
    <button id="about">About</button>
    <button id="projects">Projects</button>
    <button id="contact">Contact</button>
    
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script>
    <script type="text/javascript" src="js/elegant.js"></script>
    
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/background.js"></script>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

从这里复制JS代码:https://github.com/fralec/ElegantJS/blob/master/script/elegant.js 并使用此新文件作为elegant.js的脚本源,而不是rawgit url脚本源。

然后按照相同的格式将新按钮添加到代码中:

facebook: { id: null, faIcon: "facebook", color: "#3b5998", url: "https://www.facebook.com/", target: null}, facebook - 新按钮的名称

id - //如果您需要此网站的ID,请将其放在此处,保持为空

faIcon - //为此按钮添加所需的Font Awesome图标

颜色 - //这是悬停颜色

网址 - 您希望该按钮带您进入的网址

现在在你的js文件中,而不是这个:

facebook: { id: '' } 这样做

newButtonName: { id: '' }, otherNewButtonName: { id: '' }

现在去劫持别人的代码吧! - )