When implementing a slider with a fade effect, there seems to be an issue with the placement of widgets on the homepage. The problem arises from the margin-top setting as when images change in the slider, the widgets clash with the slider. During the transition between images, the widgets seem to consider the margin-top from the menu bar, but once the image is displayed on the slider, it takes the margin-top from where the slider starts. Below is the code snippet:
Can JavaScript be placed in the HTML file within the body tag?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js?load=effects"></script>
<script type="text/javascript">
function ShowEffect(element){
new Effect.Appear(element, {duration:5, from:0, to:1.0});
}
function FadeEffect(element){
new Effect.Fade(element, {duration:5, from:1.0, to:0});
}
var i = 0;
var path = new Array();
// LIST OF IMAGES
path[0] = "/image_1.gif";
path[1] = "images/pic1.png";
path[2] = "images/pic2.jpg";
path[3] = "images/pic3.jpg";
path[4] = "images/pic4.jpg";
function swapImage_0(){
document.slide.src = path[i];
if(i < path.length -1) i++; else i = 0;
setTimeout("FadeEffect('hideshow')",4000);
setTimeout("ShowEffect('hideshow')",5000);
setTimeout("swapImage_0()",5000);
}
window.onload = swapImage_0;
</script>
<div id="hideshow">
<img height="260" name="slide" src="images/pic1.png" width="1350"/>
</div>
<div id="slider">
<a href="https://#" title="Learn More" class="slider1" target="_blank"></a>
<a href="https://#" title="Learn More" class="Slider2" target="_blank"></a>
<a href="https://#" title="Learn More" class="Slider3" target="_blank"></a>
</div>
The CSS code provided below pertains only to the slider or widgets:
#slider{
height:240px;
width:1350px;
margin-top:400px;
background-color:#000000;
}
.slider1 {
background-image: url('images/slider1.png');
height: 240px;
width: 245px;
margin: 0px 200px;
padding-left:10px;
float: left;
-webkit-transition: all ease 0.3s;
-moz-transition: all ease 0.3s;
-o-transition: all ease 0.3s;
-ms-transition: all ease 0.3s;
transition: all ease 0.3s;
z-index: 4;
}
.slider1:hover{
background-position: 245px 0px;
box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.8);
}
.slider2 {
background-image: url('images/slider2.png');
height: 240px;
width: 245px;
margin-top:0px;
margin-left:-100px;
padding-left:9px;
float: left;
-webkit-transition: all ease 0.3s;
-moz-transition: all ease 0.3s;
-o-transition: all ease 0.3s;
-ms-transition: all ease 0.3s;
transition: all ease 0.3s;
z-index: 4;
}
.slider2:hover{
background-position: 245px 0px;
box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.8);
}
.slider3 {
background-image: url('images/slider3.png');
height: 240px;
width: 245px;
margin-top:0px;
margin-left:85px;
padding-left:9px;
float: left;
-webkit-transition: all ease 0.3s;
-moz-transition: all ease 0.3s;
-o-transition: all ease 0.3s;
-ms-transition: all ease 0.3s;
transition: all ease 0.3s;
z-index: 4;
}
.slider3:hover{
background-position: 245px 0px;
box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.8);
}