I just got back to html, javascript and jquery and i'm a bit rusty. I've mostly been doing objective-c for a while and getting back to jquery is a little difficult. I'm trying to use the jQuery fadeIn and fadeOut bit but its not working for some reason... Here's the html and js I've been working on :
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js">
function showImg(2img) {
$(2img).fadeIn('slow', function() {
// Animation complete
});
}
function hideImg(2img) {
$(2img).fadeOut('slow', function() {
// Animation complete
});
}
</script>
<body>
<table width="1659" height="701" border="0" align="center">
<tr>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img1" src="" width="232" height="232" alt="" onmouseover="showimg(2img1)" onmouseout="hideimg(2img1)" style="position: relative; top: 0; left: 0;"/>
<img id="2img1" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img2" src="" width="232" height="232" alt="" onmouseover="showimg(2img2)" onmouseout="hideimg(2img2)" style="position: relative; top: 0; left: 0;"/>
<img id="2img2" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img3" src="" width="232" height="232" alt="" onmouseover="showimg(2img3)" onmouseout="hideimg(2img3)" style="position: relative; top: 0; left: 0;"/>
<img id="2img3" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img4" src="" width="232" height="232" alt="" onmouseover="showimg(2img4)" onmouseout="hideimg(2img4)" style="position: relative; top: 0; left: 0;"/>
<img id="2img4" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img5" src="" width="232" height="232" alt="" onmouseover="showimg(2img5)" onmouseout="hideimg(2img5)" style="position: relative; top: 0; left: 0;"/>
<img id="2img5" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
</tr>
</table>
</body>
I think you'd find it better to do this:
$(function() {
$('table > div > img:first').hover(function() {
showImg($(this).next());
}, function() {
hideImg($(this).next());
});
});
This way you wont be replicating the onmouseover and onmouseoout code in your html.
The errors in your code are - No # for the id of the images to fade, although it seems to work in chrome I don't know if it will work as expected in every browser, also the function names don't have the same case.
$(2img) should be $('#2img') and that's it
$(2img) should be $('#'+2img) and invoke the function like showImg("2img2")
DEMO
$('.tb td').each(function(){
$(this).find('img').wrapAll('<div />');
$('.tb td div').css({position:'relative'});
$(this).find('img:eq(1)').css({position:'absolute', left:'0px', top:'0px'}).hide();
});
$('.tb td div').hover(function(){
$(this).find('img:eq(1)').stop().fadeTo(400,1);
},function(){
$(this).find('img:eq(1)').stop().fadeTo(400,0);
});
Related
I'm hoping to add a very simple 'Resizable' function to each image. Like a single handle in the bottom right that allows users to resize them. For some reason, each time I try and insert the Resizable function into the script, the whole thing stops working. Right now it works great for dragging. Any tips? Thanks in advance!
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"/>
<div class="container">
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage8" width="190px" src="https://static.showit.co/file/02iVvuYJTPuHVo0bvmtfPw/118367/screen_shot_2022-06-09_at_4_29_57_pm.png" alt="bridal" style="position: absolute; left: 140px; top: -10px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage2" width="200px" src="https://static.showit.co/file/SniVsCT4TI6vlO11MeCT6Q/118367/pexels-amina-filkins-5425137.jpg" alt="pampasvase" style="position: absolute; left: 40px; top: 130px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage2" width="210px" src="https://static.showit.co/file/8kXF2aZnTFWacjGrsydtaw/118367/pexels-photo-5359324.jpg" alt="tent" style="position: absolute; left:250px; top: 350px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage9" width="180px" src="https://static.showit.co/file/ezoxZmgvQeyemX5jBU4P7g/118367/kaboompics_woman_s_legs_with_palm_shadow.jpg" alt="palmshadow" style="position: absolute; left: 285px; top: 150px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage3" width="190px" src="https://static.showit.co/file/O28TqyRjRtSLTMVN4lCgEw/118367/kaboompics_a_woman_in_a_brown_sweater_with_a_black_hat_on_her_head.jpg" alt="girlinhat" style="position: absolute; left: 600px; top: 100px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage12" width="200px" src="https://static.showit.co/file/5NDU0460Q8iptTNyt07LjA/118367/jonathan-borba-p1b9ztwa0di-unsplash.jpg" alt="dance" style="position: absolute; left: 890px; top: 370px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage12" width="190px" src="https://static.showit.co/file/801y1OPPQde-Zvl-zd4zbg/118367/screen_shot_2022-06-09_at_4_20_29_pm.png" alt="twigs" style="position: absolute; left: 870px; top: 10px;">
</p>
</div>
<div id="terracotta" class="draggableContainer">
<p>
<img class="draggableImage12" width="200px" src="https://static.showit.co/file/X5Z4ojapT2CA69e4yzFspA/118367/screen_shot_2022-06-09_at_4_18_25_pm.png" alt="chair" style="position: absolute; left: 750px; top: 300px;">
</p>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<script>
$(function() {
$(".draggableContainer").draggable({
stack: ".draggableContainer",
});
});
</script>
How to convert div#WareHouse with SVG inside to image, then downloaded and center the div#WareHouse.I want to generate div#WareHouse as image code after clicking submit:
<div id="WareHouse">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 48px; left: 8px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 76px; left: 56px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 104px; left: 104px;">
<img width="80"
src="http://rgrzymala.pl/2.svg" style="top: 132px; left: 152px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 160px; left: 200px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 188px; left: 248px;">
<img width="80" src="http://rgrzymala.pl/2.svg"
style="top: 216px; left: 296px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 244px; left: 344px;"><img width="80" src="http://rgrzymala.pl/2.svg" style="top: 272px; left: 392px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 300px; left: 440px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 328px; left: 488px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 356px; left: 536px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 384px; left: 584px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 412px; left: 632px;">
<img width="80"
src="http://rgrzymala.pl/2.svg" style="top: 440px; left: 680px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 468px; left: 728px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 496px; left: 776px;">
<img width="80" src="http://rgrzymala.pl/2.svg"
style="top: 524px; left: 824px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 552px; left: 872px;">
<img width="80" src="http://rgrzymala.pl/2.svg" style="top: 580px; left: 920px;">
</div>
I tried in the html2canvas library but to no avail. Apparently, Maybe it does not support SVG. Here is a link!
I think the best approach would be making use of a canvas from the get-go.
You can then use JS as you have to draw images on the canvas (using your SVGs), like so:
var img = new Image();
img.onload = function() {
ctx.drawImage(img, 0, 0);
}
img.src = "http://upload.wikimedia.org/wikipedia/commons/d/d2/Svg_example_square.svg";
Note that drawImage accepts the image as well as X and Y coordinates. See existing question for more: Drawing an SVG file on a HTML5 canvas
Once you have drawn your SVGs as you'd like to canvas, you can make use of .toDataURL() on your canvas. Something like this:
var canvas = document.getElementById('canvas');
var dataURL = canvas.toDataURL();
The above will return a base64 encoded string, which in turn could be output to the browser to prompt saving. The following outlines this really well: How To Save Canvas As An Image With canvas.toDataURL()?
There is also a library to help with the conversion and saving: canvas2image
I am new here and this is my first question for an assignment for class. I am trying to get an image rotation to work in javascript and it is not working for me. Can someone help? I tried console logging and everything is calling fine.
I have this code within another function for when the end user clicks on a button it triggers the rotation
t = setInterval(scrollImages, 50);
function scrollImages() {
var coverBarDiv = document.getElementById("coverBar");
var images = coverBarDiv.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
var left = images[i].style.left.substr(0, images[i].style.left.length - 2);
if (left <= -86) {
left = 532;
}
images[i].style.left = (left - 1) + "px";
}
}
#coverBar {
height: 115px;
left: 182px;
overflow: hidden;
position: absolute;
top: 560px;
width: 440px;
}
#cover img {
position: absolute;
top: 0;
}
<div id="coverBar">
<img src="images/coverMatrix.jpg" width="82" height="115" style="left: 0px;">
<img src="images/coverDeadRingers.jpg" width="82" height="115" style="left: 88px;">
<img src="images/coverDrStrangelove.jpg" width="82" height="115" style="left: 176px;">
<img src="images/coverFuturama.jpg" width="82" height="115" style="left: 264px;">
<img src="images/coverHolyGrail.jpg" width="82" height="115" style="left: 356px;">
<img src="images/coverRaisingArizona.jpg" width="82" height="115" style="left: 444px;">
<img src="images/coverRobotChicken.jpg" width="82" height="115" style="left: 532px;">
</div>
It is all fine! There was just a typo in CSS selector : #cover img should be #coverBar img
t = setInterval(scrollImages, 20);
function scrollImages() {
var coverBarDiv = document.getElementById("coverBar");
var images = coverBarDiv.getElementsByTagName("img");
for (var i = 0; i < images.length; i++) {
var left = images[i].style.left.substr(0, images[i].style.left.length - 2);
if (left <= -86) {
left = 532;
}
images[i].style.left = (left - 1) + "px";
}
}
#coverBar {
height: 115px;
left: 20px;
overflow: hidden;
position: absolute;
top: 60px;
width: 440px;
}
#coverBar img {
position: absolute;
top: 0;
}
<div id="coverBar">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 0px;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 88px;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 176px;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 264px;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 356px;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 444px;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQRlq8No0dCjQXEsDTge4boAr22X6m8gVWIYSAkMwj6JYqCC9U" width="82" height="115" style="left: 532px;">
</div>
So I am trying to simply scroll left and right when someone hovers over arrows. I forked another JSFiddle and copied the html/css from my website I'm trying to do this on. Here it is: https://jsfiddle.net/31hf4e0h/
Right now it scrolls all the way to the right when you hover over either arrow, but I want the #before arrow to make it scroll to the left. Is there an easy way to do this? Or a more simple way to achieve this effect generally?
Here is the code:
$(function() {
var $container = $('#object-nav ul'),
scroll = $container.width();
$('#after').hover(function() {
$container.animate({
'scrollLeft': scroll
},{duration: 2000, queue: false});
}, function(){
$container.stop();
});
$('#before').hover(function() {
$container.animate({
'scrollLeft': scroll
},{duration: 2000, queue: false});
}, function(){
$container.stop();
});
});
Thanks!
this is perfect solution for on hover left and right scroll. jsfiddle
function loopNext(){
$('#sliderWrapper').stop().animate({scrollLeft:'+=20'}, 'fast', 'linear', loopNext);
}
function loopPrev(){
$('#sliderWrapper').stop().animate({scrollLeft:'-=20'}, 'fast', 'linear', loopPrev);
}
function stop(){
$('#sliderWrapper').stop();
}
$('#next').hover(function () {
loopNext();
},function () {
stop();
});
$('#prev').hover(function () {
loopPrev();
},function () {
stop();
});
#sliderWrapper {
left: 40px;
width: calc(100% - 80px);
white-space: nowrap !important;
height: 100%;
position: relative;
background: #999;
overflow-x: hidden;
}
img {
position: relative;
top: 50%;
transform: translateY(-50%);
}
#next {
height: 100%;
position: absolute;
right: 0;
background: #555;
z-index: 1;
}
#prev {
height: 100%;
position: absolute;
left: 0;
background: #555;
z-index: 1;
}
#imageSlider {
width: 100%;
height: 150px;
position: relative;
overflow: hidden;
}
#imageSlider img{width:100px; height:100px;}
::-webkit-scrollbar {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id="imageSlider">
<div id="prev">
<img src="" width="40px" />
</div>
<div id="next">
<img src="" width="40px" />
</div>
<div id="sliderWrapper">
<img src="" height="90px;" />
<img src="" height="90px;" />
<img src="" height="90px;" /><img src="" height="90px;" />
<img src="" height="90px;" />
<img src="" height="90px;" />
<img src="" height="90px;" /><img src="" height="90px;" />
<img src="" height="90px;" /><img src="" height="90px;" /><img src="" height="90px;" /><img src="" height="90px;" /><img src="" height="90px;" /><img src="" height="90px;" /><img src="" height="90px;" />
</div>
</div>
If you want to scroll right, you still have to use 'scrollLeft', but you can scroll to right by specifying the number of pixels.
Try something like this:
$('#before').hover(function() {
$container.animate({
'scrollLeft': -100
},{duration: 2000, queue: false});
}
The below code is a slider that manipulates between two dividers, previous and next. Each divider represents a set of ten images, as you can see in two parallel vertical lines. I'm trying to make each divider 2 parallel horizontal lines (5 images on each line), However it's getting messed up and the 2 dividers are getting connected. Any help please?
HTML:
<div id="wrapper">
<div id="nav">
<button id="prev" disabled><<<</button>
<button id="next">>>></button>
</div>
<div id="mask">
<div id="item1" class="item">
<a name="item1"></a>
<div class="content">
<img id="image1" src="http://placehold.it/350x150" />
<img id="image2" src="http://placehold.it/350x150" />
<img id="image3" src="http://placehold.it/350x150" />
<img id="image4" src="http://placehold.it/350x150" />
<img id="image5" src="http://placehold.it/350x150" />
<img id="image6" src="http://placehold.it/350x150" />
<img id="image7" src="http://placehold.it/350x150" />
<img id="image8" src="http://placehold.it/350x150" />
<img id="image9" src="http://placehold.it/350x150" />
<img id="image10" src="http://placehold.it/350x150" />
</div>
</div>
<div id="item2" class="item">
<div class="content">
<img id="image1" src="http://placehold.it/350x150" />
<img id="image2" src="http://placehold.it/350x150" />
<img id="image3" src="http://placehold.it/350x150" />
<img id="image4" src="http://placehold.it/350x150" />
<img id="image5" src="http://placehold.it/350x150" />
<img id="image6" src="http://placehold.it/350x150" />
<img id="image7" src="http://placehold.it/350x150" />
<img id="image8" src="http://placehold.it/350x150" />
<img id="image9" src="http://placehold.it/350x150" />
<img id="image10" src="http://placehold.it/350x150" />
</div>
</div>
</div>
</div>
CSS:
#wrapper {
width: 500px;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-color: #ccc;
overflow: hidden;
}
#nav button {
position: absolute;
top: 100px;
}
#prev {
left: 40px;
}
#next {
right: 40px;
}
#mask {
width: 5000px;
height: 100%;
background-color: #eee;
}
.item {
width: 500px;
height: 100%;
float: left;
background-color: #ddd;
}
.content img {
height: 100px;
width: 100px;
float:left;
margin-right: 4%;
margin-bottom: 6%;
}
.content {
width: 45%;
height: 220px;
top: 20%;
margin: auto;
background-color: white;
position: relative;
}
.content a {
position: relative;
top: -17px;
left: 170px;
}
.selected {
background: #fff;
font-weight: 700;
}
.clear {
clear:both;
}
JQUERY:
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
src="js/jquery.scrollTo.js"
$(document).ready(function () {
function shift(direction) {
var
$mask = $('#mask'),
items = $('.item').size(),
currentItem = $mask.data('currentItem'),
newItem;
if (currentItem == undefined) {
currentItem = 0;
}
newItem = currentItem + direction;
$mask.data('currentItem', newItem).animate({marginLeft: -500 * newItem});
if (newItem == 0) {
$("#prev").prop('disabled', true);
} else {
$("#prev").prop('disabled', false);
}
if (newItem == items - 1) {
$("#next").prop('disabled', true);
} else {
$("#next").prop('disabled', false);
}
}
$('#prev').click(function() {
return shift(-1);
});
$('#next').click(function() {
return shift(1);
});
});
JSFIDDLE: http://jsfiddle.net/2ghovmww/
As I see it you can achieve what you want with display:inline for each horizontal block, but as you have implemented it, the width of your container is smaller than the width of five elements in a row, so they can't be displayed. If you use overflow:hidden you will have two rows but the elements that exceed the width of the container will be hidden. So first you must adjust the width of the container and its parent elements.