Image slider (cycle-loop) onmouseover image-thumbn

2020-03-07 07:17发布

I have made a simple thumbnail image showcase to preview in #imgbig viewer. I hover on thumbnail it shows it in the image box. I have five different thumbnails.

Sorry for not including images here. When I do mouseover on thumbnail I want it to show the image slider in the #imgbig instead of the same pic.

It will show an image (cycle) slider matching the pic of the same thumbnail in different angles either from an array of image loop or images from the folder.

Like an image showcase, showing the thumbnail image in different angles inside the #imgbig when the thumbnail is onmouseover and goes back to default image onmouseout.

For now I have added an image slider with matching images with the first thumbnail and the slider in its #imgbig is working too.

But I am not to keep the slider in stop position till I mouseover the image. It starts playing as soon I load the page and it gets faster in loop when I mouseover the image and keeps getting faster in loop.

var i = 1;

function slider() {
  var imgg = document.getElementById("imgbig");
  imgg.src = "https://loremflickr.com/320/240?random=" + i;
  i++;
  if (i > 10) {
    i = 1;
  }
}
function timer()
{
setInt = setInterval(slider,1000);
}
function slideroff()
{
i=1;
clearInterval(setInt);
var imgg=document.getElementById("imgbig");
imgg.src = "http://placehold.it/400x400";
}
.imgboxdiv {
  width: 1000px;
  margin: 0 auto;
  text-align: center;
}

.imageshowcase {
  width: 400px;
  height: 400px;
  background-color: ;
  margin-bottom: 20px;
}

.imageshowcase img {
  width: 400px;
  height: 400px;
  border: 3px solid red;
}

.imgparameter {
  width: 150px;
  height: 150px;
  border: 3px solid red;
}

*
{
	margin:0 auto;
	padding:0;
	box-sizing:border-box;
}

body
{
	margin:0 auto;
	padding:0;
	background-color:slategrey;
}
<!DOCTYPE html>
<html>

<head>
  <title> Title </title>
  <link rel="stylesheet" type="text/css" href="css/style.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>


  <div class="imgboxdiv">
    <h1>Image slider start on mouseover thumbnail</h1>

    <div class="imageshowcase" id="imgshwcase">
      <img src="http://placehold.it/400x400" id="imgbig">
    </div>

    <img src="https://loremflickr.com/320/240?random=1"  onmouseover="slider()" id="img1" class="imgparameter">

  </div>

</body>

</html>

1条回答
Animai°情兽
2楼-- · 2020-03-07 07:24

i fixed it myself..

var i = 1;
var setInt;

function  slider()
{
	var imgg=document.getElementById("imgbig");
	imgg.src = "https://loremflickr.com/320/240?random=" + i ;
	i++;
	if(i>5)
	{
	i=1;
	}
}
function timer()
{
	setInt = setInterval(slider,2000);
}
function slideroff()
{
	i=1;
	clearInterval(setInt);
	var imgg=document.getElementById("imgbig");
	imgg.src = "http://placehold.it/400x400";
}
*
{
	margin:0 auto;
	padding:0;
	box-sizing:border-box;
}

body
{
	margin:0 auto;
	padding:0;
	background-color:slategrey;
}

.imgboxdiv
{
	width:1000px;
	margin:0 auto;
	text-align:center;
}
.imageshowcase
{
	width:400px;
	height:400px;
	background-color:;
	margin-bottom:20px;
}
.imageshowcase img
{
	width:400px;
	height:400px;
	border:3px solid red;
}
.imgparameter
{
	width:150px;
	height:150px;
	border:3px solid red;
}
<!DOCTYPE html>
<html>
<head>
	<title> Title </title>

</head>

<body>

<div class="imgboxdiv" >
<h1>Image slider start on mouseover thumbnail</h1>

<div class="imageshowcase" id="imgshwcase">
<img src="http://placehold.it/400x400" id="imgbig">
</div>

<img src="https://loremflickr.com/320/240?random=1" onmouseover="timer()" onmouseout="slideroff()" id="img1" class="imgparameter">

</div>

</body>
</html>

查看更多
登录 后发表回答