Changing images in Javascript [duplicate] - javascript

This question already has answers here:
How to fade loop background images?
(3 answers)
Closed 8 years ago.
I have this script that changes images fine, but not smoothly. How can I change this so they change smoothly?
//--------AutoPlay select--------------------------
function autoPlaySlider(id){
var recNumber = parseInt(id)+1;
if(jQuery("#simg_"+recNumber).length){
jQuery("#rt-header-surround")
.attr("style",'background-image:url('+jQuery("#simg_"+recNumber).attr("imgpath")+')');
}else{
jQuery("#rt-header-surround")
.fadeOut()
.attr("style",'background-image:url('+jQuery("#simg_"+lastone).attr("imgpath")+')');
}
}

$().fadeOut(); applies to the element, not it's background.
If you want to animate CSS properties your best bet is to use jQuery.animate();

Related

how to run a function after html value change [duplicate]

This question already has answers here:
jQuery Event : Detect changes to the html/text of a div
(13 answers)
Closed 5 years ago.
I am doing a simple hover scrollbar project. I want to change the height of thumb when someone change the contents in html tag by prepend(),append(),html()..etc. how can I do this? I googled it and found answers like
$('.class').html('value').trigger(somefunction())
But it is not the answer. Because I am not the developer of other js codes. I want to do this with only my script file.
here is my project :-
https://github.com/rameshkithsiri/hoverscroll
Here is way of doing so , you can use DOMSubtreeModified events. But look out It before using it.
$("body").on('DOMSubtreeModified', ".myCLASS", function() {
alert($(this).html());
});
setTimeout(function(){ $(".myCLASS").html("my Test") }, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="myCLASS"></div>

JavaScript get background color in variable [duplicate]

This question already has answers here:
why javascript this.style[property] return an empty string? [duplicate]
(2 answers)
Closed 6 years ago.
I've been trying to get a fade in and out for a background image for a site, and I have been trying to get the background color of a div into a variable, this is what I've tried:
elem = document.getElementById('nav');
bgColor = elem.style.backgroundColor;
But once I try to alert the variable bgColor like: alert(bgColor) all I get alerted is empty in the text box. I've looked around on some Stack questions and I've tried everything that is told there and it doesn't seem to put the physical color into a variable.
window.getComputedStyle is the solution. Otherwise you'll get the "direct" styles that are empty.

Check whether a CSS class has a particular attribute or not [duplicate]

This question already has answers here:
How to get a style attribute from a CSS class by javascript/jQuery?
(8 answers)
Closed 8 years ago.
It might be repeated question but still need of time is that I want a solution.
I am new to CSS and jQuery, so here is what I am looking for.
I have a css like this
.my-selector {
background-size: cover;
something-here1 : 2;
}
Now I want to check whether this my-selector has backgroud-size as one of the elements or not, if it has then I want to add new element in same selector.
This I want to do in JavaScript or using jQuery
btw: jQuery IS javascript.
if (!$(this).hasClass("my-selector")) {
//rlemons post [link below] deals with this
}
look here for rlemon's anwer for the this part

Get div attribute value on page load [duplicate]

This question already has answers here:
How do I check if an element is hidden in jQuery?
(65 answers)
Closed 8 years ago.
I want to get value of div attribute. Like I want to know whether the div is "display:block;" or "display:none" at the time of page load. If "display:block;" then it will be "display:block;" after the page load again if not then "display:none". Can anyone help me with jquery method or code?
Do this:
<script>
$(document).ready(function(){
var x =$("#divId").css("display");
alert(x);
});
</script>

Only one jQuery event runs per refresh [duplicate]

This question already has answers here:
Find currently visible div in jquery
(5 answers)
Closed 3 years ago.
Only one jQuery event runs per refresh of the page. What am I doing that's so wrong?
$("#contact_link_email").on("click",function(){
$("#contact-form").replaceWith('<h2>Email heading</h2>');
});
$("#contact_link_facebook").on("click",function(){
$("#contact-form").replaceWith('<h2>Facebook heading</h2>');
});
$("#contact_link_twitter").click(function(){
$("#contact-form").replaceWith('<h2>Twitter heading</h2>');
});
$("#contact_link_gplus").click(function(){
$("#contact-form").replaceWith('<h2>GPlus heading</h2>');
});
Once one of those events runs, $("#contact-form") doesn't reference anything. If you want to replace it with something, try making that something have the same id.

Categories

Resources