addclass on hover not working - html

I want to hover on an element (an imagemap area, actually but I made it a simple div for this example) and create an animation on a different div element. Since they're not child or sibilings I had to use java and addclass but it's not working. It looks like the trigger element is not recognized and if I hover it nothing happens
<div class="testHover">
<p>Hover me to change color</p>
</div>
<div id="timeLine">
<div id="primaGuerraMondiale">
<h2>Content</h2>
</div>
</div>
css
#primaGuerraMondiale {
background: green;
}
.animated {
color:white;
}
javascript
$('.testHover').hover(function() {
$('#primaGuerraMondiale').addClass('animated');
}, function() {
$('#primaGuerraMondiale').removeClass('animated');
});
Here is the fiddle https://jsfiddle.net/elisapessa/yzLe803n/

You need jQuery 1.9.1 and above to make it work. The code is right.

In the left hand panel in the jsfiddle, there is a section called "Add Resources". Click this, then add the URL into the field and click the + button. This will add your resource (JS or CSS) to the page. After that you click on run and check it:

Related

Bootsrap Affix not working

I have added the library for Bootstrap and data-spy attribute where I want to make the div fix when I scroll the page down. But it doesn't work, I have almost tried everything, but not able to figure out the problem.
Is is something like the data-spy attribute doesn't work on class = "row" ?
Here's my code for HTML.
<div class="row">
<h4> HEADING </h4>
<h5>
<div class="row" data-spy="affix" data-offset-top="10">
dsds
Date : <input type="date" name="graph_date" id="graph_date">
</div>
<div class="row">
<div class="graph-hourly">
<div class="loader" id="chart_loader">
<p>Loading...</p>
</div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_hourly"></div>
</div>
</div>
</div>
and some css :
.affix {
top : 0;
width: 80%;
}
after searching for some solutions, I've added this also,
.affix-top {
width: 100%;
}
.affix-bottom {
position: absolute;
width: 100%;
}
but this solution also dosen't worked for me.
Not sure what the problem is in your case. I copied and pasted your code into a jsfiddle with the bootstrap library and the affix class did work. Though, it worked badly because it affixed the row right when you started scrolling.
Looks like Bootstrap doesn't have a way to set the offset to the current position of the element so I added the following javascript to make it work.
$('#affix-this').affix({
offset: {
top: $('#affix-this').offset().top
}
})
(#affix-this should be changed to the id of the row you want to affix.)
Note the $('#affix-this').offset().top. This makes sure the element gets affixed right when you reach the element's current position.
Second, I removed the html attributes that you had for the affixing.
<div class="row">
<h4> HEADING </h4>
<div class="row" id="affix-this">
dsds Date :
<input type="date" name="graph_date" id="graph_date">
</div>
<div class="row">
<div class="graph-hourly">
<div class="loader" id="chart_loader">
<p>Loading...</p>
</div>
<div id="chart_hourly"></div>
</div>
</div>
Notice the affix-this id was added to the row that you want to affix.
Here is a working JSFiddle with these changes so you can see it in action: https://jsfiddle.net/heraldo/6s4u26m3/4/
First of all delete top:0; from affix class because it will make a issue for you.
now you have two methods pick a one :
1
adding data-spy="affix" which is works fine for me
2
same result ass data-spy but you will need some styling after you complete your page
by adding a position Property for input tag
as ex. :
CSS:
sticky{
position:fixed;
}
and HTML :
<input type="date" name="graph_date" class="sticky" id="graph_date">
Update 1
this Jquery code can detect a scroll event so when user scroll down it will make the div tag sticky or "affix"
$(function() {
$(window).scroll(function() {
var aTop = "100";
if ($(this).scrollTop() >= aTop) {
$('#affix-this').css( "position", "fixed" );
$('#affix-this').css( "top", "0" );
$('#affix-this').css( "width", "100%" );
}
});
});
change the aTop variable with the height you want (in pixel) so when the user scroll down 100px the div become sticky
a JSfiddle example
Update 1.1
a bit smarter Jquery code do the same but get the height automatically from a another element this can be good if you format your page to something similar to this
$(function() {
$(window).scroll(function() {
var aTop = $('id').height();
if ($(this).scrollTop() >= aTop) {
$('#affix-this').css( "position", "fixed" );
$('#affix-this').css( "top", "0" );
$('#affix-this').css( "width", "100%" );
}
});
});
Make sure the element to which you're adding data-spy="affix has been created in the DOM before your Bootstrap scripts load. I ran into an issue where I was adding data-spy="affix" in my HTML, but it was wrapped up in a section that wasn't rendering, thanks to data-ng-if. My HTML was created after my Bootstrap had loaded, so the <div> I wanted to stick to the top of the screen never stayed in a fixed position. If you can, use data-ng-show, or something that merely hides HTML, rather than prevents it from being created on page load.

How to hide/display an anonymous div without affect other divs

I want to hide an anonymous-child div which has a child-div also. I want also to display the anonymous div by clicking on div#child2.
I don't have any authority to change/add/remove ids or classes.
So I did this:
<div id="parent">
<!-- the anonymous div which I want to hide and display by clicking on div#child-2 -->
<div>
<div id="Container1" >
<div id="Container1">
<object>.....</object>
</div>
</div>
</div>
<div onclick="appear()" id="child-2">
<div id="child-of-child"></div>
</div>
</div>
CSS
div#parent div:first-child {
display: none;
}
Javascript
<script type="text/javascript">
function appear() {
document.getElementById("Container1").document.display="block !important";
}
</script>
The problem is that this type of css has affected the div#child-of-child and div#Container1 because the css reffering to every first child of any div.
So, my first question is:
How can I hide the anonymous div without having any effect to another div and display that later by clicking on div#child-2.
Second:
In this type of javascript code the styling of "block !important" works as it is?
Third:
The div#child2 doesn't have any content by itself. It includes another div which has content. If I set on div#child2 an event like onclick="appear()"; it works?
Forth:
In case that there is no way to avoid any effect to other divs is there any way to display the anonymous div and div#Container1?
Try this to only hide the first child within the #parent div:
div#parent div:first-child div:first-child {
display: none;
}
EDIT
To make Container1 appear afterwards, do the following in js (notice: I removed `!important' as I don't believe that is allowed, removing it made the code work - you can try it out below through the Fiddle link):
function appear() {
document.getElementById("Container1").style.display="block";
}
FIDDLER

How to set the background color of an element in my case

I am trying to create a bootstrap accordion for my app. I also have background color in its parent element. My problem is that when I expand my accordions, it extends the height of my page and the background color doesn't cover the extended area.
my html
<div id='wrapper>
<accordion id='accordion' close-others="false">
<accordion-group>
<accordion-heading >
<h2 class='title'>Title 1</h2>
</accordion-heading>
<div id="first" class="panel-collapse collapse in">
//contents...
</div>
</accordion-group>
//I have 5 to 6 accordion group.
</accordion>
</div>
CSS:
//I used height:100% and it looks fine when the page first loaded but not after //user //expand all the accordion.
#wrapper{
background-color: red;
height: 100%;
display: block;
}
Can anyone help me about it? Thanks a lot!
Looking through the documentation I noticed you could catch the event shown.bs.collapse which
is fired when a collapse element has been made visible to the user
(will wait for CSS transitions to complete).
So you could try something like:
$('#myCollapsible').on('shown.bs.collapse', function () {
document.getElementById('wrapper').style.backgroundColor="red";
})
Edit: if that does not work try show.bs.collapse

making div invisible and after clicking link make it visible

I have two different div's I want to make one of them invisible and after clicking the link or button I want it to be visible and the other invisible. I don't know javascript so I know only HTML and CSS. Can I do that with only using HTML&CSS and How can I do that? Thanks.
You need to use jQuery for this.
Just add this line to your head tag:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js">
If your HTML is like this:
<div id="div1">This is div1</div>
<div id="div2">This is div2</div>
<button id="button1">Toggle divs</button>
CSS:
#div2 {
display:none;
}
At the bottom of your page, just before the closing tag </body> add the following JavaScript:
<script>
$("#button1").on("click", function () {
$("#div1, #div2").toggle();
}
</script>
Here's a link for a similar example:
http://api.jquery.com/toggle/#entry-examples

How can I swipe/scroll horizontally with acceleration/deceleration through a set of images in a DIV on a mobile site using only HTML and CSS

I want to allow mobile site users to swipe/scroll through a list of icons.
The icons are div tags containing img tags.
The user should be able to swipe the container, scrolling/sliding the elements left or right.
The images need to slide smoothly with acceleration and deceleration.
Needs to work on iOS and Android.
We needed something like this sometime back, so I made a demo for it at that time. It's pretty basic, but it'll lay up all the ground work you need. First, lets start with the markup :
Markup
Since you mentioned jQM in the tag section of your question, Im gonna go with jQM [data-role=page] markup. You'd have a structure like this :
<div data-role="page">
<div data-role="header" data-theme="b">
<h1>Slideshow</h1>
</div>
<div data-role="content">
<div class="images">
<!--your images here -->
</div>
</div>
</div>
So you'd put all your images in the div with class=images. A particular group of images were encapsulated within a tags like this :
<a href="#">
<img src="25AC.jpg" />
</a>
<a href="#">
<img src="nature.jpg" />
</a>
<!--so on-->
You'd place this inside div.images. So that's about the markup we have.
CSS
The stylesheet part is simple.
.images {
height : 280px;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
background-color : #272722;
}
.images a{
padding : 14px 5px 0px 5px;
margin: 5px 3px 0px 3px;
vertical-align: middle;
display: inline-block;
}
images img {
max-width: 100%;
max-height:512px;
}
Important properties to note here :
The overflow-x, overflow-y properties : The former needs to be enabled and the latter needs to be disabled. Only then the scroll will happen when you swipe right or left.
The white-space property : This is important to make the images come in a straight horizontal layout.
The max-width property : This is for scaling the images on mobile.
That's it! You're done!
Extras
I just added a popup to show the image when its tapped so that I'd be able to demonstrate the event handling. Here's the popup :
<div data-role="popup" id="popupInfo" data-overlay-theme="a" data-theme="b" data-corners="false">
Close
<div id="stuff"></div>
</div>
I'd be putting the image inside div#stuff when the a surrounding the img is clicked. Here's the JS :
//pageinit event of page
$(document).on("pageinit", "[data-role=page]", function() {
//cache popup for future use
var $popup = $("#popupInfo");
//click event for "a" tag inside .images
$(this).on("click", ".images > a[href=#]", function(e) {
//prevent default action
e.preventDefault();
//clone the image inside "a"
var $img = $(this).find("img").clone();
//add the cloned image inside #stuff
$popup.find("#stuff").html($img);
//open popup()
$popup.popup().popup("open");
});
});
Demo & Code
Demo & Code at jsbin.com
Alternatives
You could try out swipejs, which is jQuery plugin which will provide a much more sophisticated functionality. Here's the link to the site.