I try to add some text right on a javascript slideshow, but somehow it doesn't work out. The text shows on the top and slideshow is looping below the text.
How can I make the text show right on images? Please take a look
<html>
<head>
<script type="text/javascript">
<!--
var image1=new Image()
image1.src="firstcar.gif"
var image2=new Image()
image2.src="secondcar.gif"
var image3=new Image()
image3.src="thirdcar.gif"
//-->
</script>
</head>
<body>
<div style="width:100px; height:56px">
<div style="width:100px; height:56px; z-index:2">Tring to add some text on the top
<div style="width:100px; height:56px; z-index:1">
<img src="firstcar.gif" name="slide" width="100" height="56" />
</div>
</div>
</div>
<script>
<!--
var step=1
function slideit(){
if (!document.images)
return
document.images.slide.src=eval("image"+step+".src")
if (step<3)
step++
else
step=1
setTimeout("slideit()",1500)
}
slideit()
//-->
</script>
</body>
</html>
you prob need position: absolute if you want to use z-index
or you can reduce the height of the img to smaller than the div container of the text
try this:
<body>
<div style="width:100px; height:56px">
<div style="position:absolute; z-index:2">Tring to add some text on the top
</div>
<div style="position: absolute;width:100px; height:56px; z-index:1">
<img src="firstcar.gif" name="slide" width="100" height="56" />
</div>
</div>
</body>
Move the text you are adding into an element below the image element, give it absolute positioning, give the containing div relative positioning, and position the text using top, left, right, or bottom.
HTML:
<div class="container">
<img src="firstcar.gif" name="slide" width="100" height="56" />
<span>Added Text Here</span>
</div>
CSS:
div.container {
position: relative;
}
span {
position: absolute;
top: 0;
}
Related
I want a div element, on which I click. Then another div element should pop up.
I tried something, but don't know, why it doesn't work.
<div class="div" onclick="myFunction()">
<img class="image" src="..." height="80px" width="80px">
<h2 class="header">text</h2>
<img class="more" src="..." height="50px" width="50px">
</div>
<script>
function myFunction() {
document.getElementById('text')
[0].classList.toggle('display')
<div class="news" onclick="myFunction()">
<img class="coronanewsimg" src="https://www.mediothek-krefeld.de/files/content-fotos/Bilder%20fuer%20Neuigkeiten%20und%20Slider/628px-Achtung.svg.png" height="80px" width="80px">
<h2 class="coronanewshead">Sonderschließzeit bis vorraussichtlich 07.03.21 aufgrund des Coronavirus</h2>
<img class="mehr-pfeil" src="pics/mehr-pfeil.png" height="50px" width="50px">
</div>
<script>
function myFunction() {
document.getElementById('coronanewstext')
[0].classList.toggle('display')
}
</script>
<div class="text">
text
</div>
You could also use this method to create a div element when the event occurs.
<!DOCTYPE html>
<html>
<head>
<title>Event handling</title>
</head>
<body>
<p>Click the button to pop up another div element.</p>
<button onclick="popDiv()">Click me</button>
<script>
function popDiv() {
var division = document.createElement("div");
division.innerText = "This is a new DIV element";
division.style.color = "blue";
division.style.margin = "10px"; //Simple styling of div
division.style.background = "whitesmoke";
division.style.border = "1px solid black";
document.body.appendChild(division);
}
</script>
</body>
</html>
Also correct upon the tag's opening and closing in your code, or this may also result in error.
simple example how on click works for an element id
<html>
<head>
<script type="text/javascript">
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>
<h1>How to display the Day, Date, Time at the touch of a button</h1>
<p id="demo">We would like it to appear hear.</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
<div id="537267839_INSERT_SLOT_ID_HERE"
style="width:768px;height:90px;margin:auto;">
<noscript>
<p align="center">
<iframe id="a1651026db" name="a1651026db" src="//oncampusweb-d.openx.net/w/1.0/afr?auid=537267839&cb=INSERT_RANDOM_NUMBER_HERE"frameborder="0" scrolling="no" width="728" height="90" align="center"display:block;>
</p>
</iframe></noscript>
</div>
<script type="text/javascript">
var OX_ads = OX_ads || [];
OX_ads.push({
slot_id: "537267839_INSERT_SLOT_ID_HERE",
auid: "537267839"
});
</script>
<script type="text/javascript" src="//oncampusweb-d.openx.net/w/1.0/jstag">
</script>
In this code I want to center the ad being placed. I can't figure out how. I tried align="center" in style and margin:auto but it doesnt work.
Try:
margin: 0 auto;
0 for the top/bottom and auto for left/right
Try using a flex box to center align child components both vertically and horizontally.
<div id="537267839_INSERT_SLOT_ID_HERE"
style="width:768px;height:90px;display:flex;justify
content:center;align-items:center;">
Wrap it:
<div style="width:100%; text-align:center">
your code goes here
</div>
How would I make my code show one image at time?
<!DOCTYPE html>
<html lang ="en">
<head>
<title> VIS</title>
<meta charset="utf-8"/>
<script type="text/javascript" >
function showImage(id){
if(document.getElementById(id).style.visibility =='visible')
document.getElementById(id).style.visibility = 'hidden';
else
document.getElementById(id).style.visibility= 'visible';
}
</script>
</head>
<body>
<div style="position: relative; visibility: visible;">
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437"
alt="Pumpkins" id="Pum"/>
<button onclick="showImage('Pum');">Pumpkins</button>
</div>
<div style="position: relative; visibility: visible;">
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437"
alt="Pumpkins" id="Straw"/>
<button onclick="showImage('Straw');">Strawberries</button>
</div>
<div style="position: relative; visibility: visible;">
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437"
alt="Pumpkins" id="Ras"/>
<button onclick="showImage('Ras');">Rasberries</button>
</div>
</body>
</html>
My code works fine, but I want it to show one image at time.When I click one of them, it will hide the other .
With my code,can show as many images as I want and as few images. How could I do this , could I send multiple ids as parameters ?
Any help would be great.
Try like this:
First get all the images and hide them , if you want any specific to be shown at load time just ignore that index.after loading you can do your button action as you are trying to.If you want to hide the rest of the visible images on button click then just get the visible image and hide it and show the clicked one.
<!DOCTYPE html>
<html lang ="en">
<head>
<title> VIS</title>
<meta charset="utf-8"/>
</head>
<body>
<div style="position: relative; visibility: visible;">
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437"
alt="Pumpkins" id="Pum"/>
<button onclick="showImage('Pum');">Pumpkins</button>
</div>
<div style="position: relative; visibility: visible;">
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437"
alt="Pumpkins" id="Straw"/>
<button onclick="showImage('Straw');">Strawberries</button>
</div>
<div style="position: relative; visibility: visible;">
<img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437"
alt="Pumpkins" id="Ras"/>
<button onclick="showImage('Ras');">Rasberries</button>
</div>
</body>
<script type="text/javascript" >
removeVisibility();
function showImage(id){
removeVisibility();
if(document.getElementById(id).style.visibility =='hidden')
document.getElementById(id).style.visibility = 'visible';
}
function removeVisibility(){
var imgs=document.getElementsByTagName('img');//get all the images
for(var i=0;i< imgs.length;i++){
imgs[i].style.visibility= 'hidden'; //hide them
}
}
</script>
</html>
I need a simple script that allows me to change the inner html of a p tag which in my case is an image to just plain text when I hover over it.
Example:
<div id="one">
<p><img src="events.png" alt="" /></p>
</div>
When i hover over the above p tag i want it to change to the text as seen below
<div id="one">
<p>Events</p>
</div>
You don't need to use javascript at all for this. This is handled very simply using css.
<div id="one">
<p>
<span>Events</span>
<img src="events.png" alt="" />
</p>
</div>
CSS:
#one p>span{ display:none; }
#one p:hover span{ display:inline; }
#one p:hover img{ display:none; }
Here's a fiddle of it in action: http://jsfiddle.net/CKpCk/
Try the following:
var html = $('#one p').html()
$('#one').hover(function(){
$('p', this).html('Events');
}, function() {
$('p', this).html(html);
})
Demo
Try this one:
<html>
<head>
<title>Try</title>
</head>
<script type="application/javascript" src="jQuery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#testHover").hover(function()
{
$("#testHover").html("Events");
});
});
</script>
<body>
<div id="one">
<p style="width:200px;"id="testHover"><img src="events.jpg" alt="" /></p>
</div>
</body>
</html>
I have the code below,and I want to images to be change with a fade,the images now are been replaced by the function 'changeBg',but they are just been replaced without fade.
how can I "merge" between the function that's changing the images and the function that in charge of the fade.
thanks.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<title>none</title>
<link rel="stylesheet" type="text/css" href="Css/design.css" >
<script src="query-1.4.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(document).ready(function() ({$('').fadeIn(1000);
});
</script>
<script language="JavaScript">
function changeBg (color) {
document.getElementById("wrapper").style.background="url(Images/"+color+".jpg) no-repeat";}
</script>
</head>
<body>
<div id="wrapper" class="wrapper">
<div class="logo"><img border="0" src="Images/logo.png" >
</div>
<div class="menu">
<img border="0" src="Images/arrowleft.png" >
<img border="0" src="Images/black.png" onclick="changeBg(this.name);" name="black">
<img border="0" src="Images/blue.png" onclick="changeBg(this.name);" name="blue">
<img border="0" src="Images/fuksia.png" onclick="changeBg(this.name);" name="fuksia">
<img border="0" src="Images/brown.png" onclick="changeBg(this.name);" name="brown">
<img border="0" src="Images/orange.png" onclick="changeBg(this.name);" name="orange">
<img border="0" src="Images/red.png" onclick="changeBg(this.name);" name="red">
<img border="0" src="Images/grey.png" onclick="changeBg(this.name);" name="grey">
<img border="0" src="Images/white.png" onclick="changeBg(this.name);" name="white">
<img border="0" src="Images/arrowright.png" >
</div>
</body>
</html>
Thanks!
If I understand you correctly, you might be able to fade the background out, change it, then fade it back in again? Like this:
function changeBg (color) {
$('#wrapper').fadeOut(1000,function(){
$(this).css('background','url(Images/'+color+'.jpg) no-repeat').fadeIn(1000);
});
}
The cross-fading (fade out while fading in) is achieved in jQuery by having the statements straigh in line and not inside functions from previos animation.
Also, I understand that you want JUST THE BACKGROUND IMAGE to fadeout and fadein; not the actual contents of the page.
To achieve that, make your background image a separate item altogether but inside of the main div you have backgrounded:
<div id='wrapper' style='position:relative' > <!-- must be relative -->
<img id='bg1' src='initial.image' style='position:absolute; top:0; left:0;
width:100%; height:100%; opacity:0.2; display:none; ' />
<img id='bg2' src='initial.imageTWO' style='position:absolute; top:0; left:0;
width:100%; height:100%; opacity:0.2; display:none; ' />
</div>
function changeBackground(which) {
$('#bg'+which).attr('src','current-image.xxx').fadeOut('slow');
which = (which = 1) ? 2 : 1;
$('#bg'+which).attr('src','next-image.xxx').fadeIn('slow');
setTimeout('changeBackground('+which+')',2000);
}
$(document).ready( function () {
$('#bg1').attr('src','image-name.xxx').fadeIn('slow');
setTimeout('changeBackground(1)',2000); //every 2 seconds?
. ......
});
In case you have various images for the "slide show", you might want to add a random
number generation for which picture to show next.