I have written a note app using Jquery but the container is stuck on load, how i can fix this bug ?
Demo : http://sallibert.com/apps/notes/notes.php
The html (simplified):
<div id="wrapper">
<div id="contentWrapper">
<div id="ntes_left_side">**Notes list and add one**</div>
<div id="ntes_right_side">**Note content and back**</div>
</div>
</div>
Js:
$(document).on('click','#ntesliste li', function(evt) {
$('#contentWrapper').animate({"left": "320px"}, "fast");
$('#zonote').focusout();
fns.textAreaPopulate(+$(this).data('id'),this);
});
$(document).on('click', '#retrlste', function() {
$('#contentWrapper').animate({"left": "0px"}, "fast");
});
$(document).on('click', '#compteurnte #ajouternote', function() {
$('#contentWrapper').animate({"left": "320px"}, "fast");
fns.addNewNote();
});
CSS:
#wrapper{
width:320px;
height:480px;
overflow:hidden;}
#contentWrapper{
width:640px;
height: 480px;
float:left;
position:relative;
}
#ntes_left_side, #ntes_right_side{
width:320px;
height: 480px;
position:absolute;
}
#ntes_right_side{
left:0px;
}
#ntes_right_side{
left:320px;
}
Related
I'm trying to make the height div.container smaller whenever the divs inside of the div.container slide out on click, but the height of the div continues to stay the same height.
I also want the div that hasn't been clicked yet to slide into place of the div that has been clicked.
Here's my JSFiddle: https://jsfiddle.net/ispykenny/soysd2zu/
Any help would be very helpful! Thanks!
and here's the code.
<div class="container">
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
<div class="two"><p>slide over on click</p></div>
<div class="three"><p>slide over on click</p></div>
.container{
background-color:green;
}
.two{
width:300px;
margin-left:auto;
margin-right:auto;
cursor:pointer;
background:#666;
text-align:center;
padding:10px;
font-size:10px;
border:1px solid black;
position:relative;
}
.three{
width:300px;
margin-left:auto;
margin-right:auto;
cursor:pointer;
background:#666;
text-align:center;
padding:10px;
font-size:10px;
border:1px solid black;
position:relative;
}
$(document).ready(function(){
$('.two').click(function(){
$(this).animate({right:"1500px"},'5000');
});
$('.three').click(function(){
$(this).animate({left:"1500px"},'5000');
});
});
Seemed like you need to make a style 'display' of your clicked div to set 'none' after animation is completed. But in this way there will not be any animation of vanishing in that empty field.
$(document).ready(function(){
$('.two').click(function(){
$(this).animate({right:"1500px"},'5000', function() {
$(this).css("display", "none")
});
$('.three').click(function(){
$(this).animate({left:"1500px"},'5000', function() {
$(this).css("display", "none")
});
});
Use slideUp to move the remaining blocks smoothly.
$(document).ready(function () {
$('.two').click(function () {
$(this).animate({
right: "1500px"
}, '5000', function() { $(this).slideUp(); });
});
$('.three').click(function () {
$(this).animate({
left: "1500px"
}, '5000', function() { $(this).slideUp(); });
});
});
Updated JSFiddle
https://jsfiddle.net/mblenton/soysd2zu/3/
$(document).ready(function () {
$( '.two' ).click(function() {
$( this).animate({
right: "1500px"
}, 1000, function() {
$(this).remove();
});
});
$( '.three' ).click(function() {
$( this).animate({
left: "1500px"
}, 1000, function() {
$(this).remove();
});
});
});
I'm trying to create a situation where on click, menu items slide out then spread out vertically. I've kind of achieved this but when the menu is closed and reopened, the menu items pickup where they left off and spread out even further!
How do I toggle or reset the vertical movement?
My jQuery:
$('.box').click(function(){
$('.tab1').toggle("slide", { direction: "left"}, 500);
$('.tab2').toggle("slide", { direction: "left" }, 500);
$('.tab3').toggle("slide", { direction: "left" }, 500);
});
$('.box').click(function(){
$('.tab1').animate({top:'+=50px'});
$('.tab3').animate({top:'-=50px'});
});
html:
<div class="square">
<div class="box">
CLICK
<div class="tab1 tab"></div>
<div class="tab2 tab"></div>
<div class="tab3 tab"></div>
</div>
</div>
css:
.square{
margin-left:100px;
}
.box{
position:relative;
width:150px;
height:150px;
background-color:#000;
color:#fff;
text-align:center;
}
.tab{
width:70px;
height:40px;
background-color:grey;
display:none;
}
.tab1{
position:absolute;
right:-70px;
top:50px;
}
.tab2{
position:absolute;
right:-70px;
top:50px;
}
.tab3{
position:absolute;
right:-70px;
top:50px;
}
JSFiddle
Create toggle functionality for the other animations as well
$('.box').click(function(){
var flag = $(this).data('flag');
$('.tab1').toggle("slide", { direction: "left"}, 500);
$('.tab2').toggle("slide", { direction: "left" }, 500);
$('.tab3').toggle("slide", { direction: "left" }, 500);
$('.tab1').animate({top: (flag ? '+=50px' : '-=50px')});
$('.tab3').animate({top: (flag ? '-=50px' : '+=50px')});
$(this).data('flag', !flag)
});
FIDDLE
I found this old post asking for a simple fade image rotator:
Looking for a simple fade javascript image rotator
and found what I was looking for:
$(function() {
$('#fader img:not(:first)').hide();
$('#fader img').css('position', 'absolute');
$('#fader img').css('top', '0px');
$('#fader img').css('left', 'auto');
$('#fader img').css('right', 'auto');
//$('#fader img').css('left', '50%');
$('#fader img').each(function() {
var img = $(this);
$('<img>').attr('src', $(this).attr('src')).load(function() {
//img.css('margin-left', -this.width / 2 + 'px');
});
});
var pause = false;
function fadeNext() {
$('#fader img').first().fadeOut().appendTo($('#fader'));
$('#fader img').first().fadeIn();
}
function fadePrev() {
$('#fader img').first().fadeOut();
$('#fader img').last().prependTo($('#fader')).fadeIn();
}
$('#fader, #next').click(function() {
fadeNext();
});
$('#prev').click(function() {
fadePrev();
});
$('#fader, .arwBtn').hover(function() {
pause = true;
},function() {
pause = false;
});
function doRotate() {
if(!pause) {
fadeNext();
}
}
var rotate = setInterval(doRotate, 4000);
});
this was the original fiddle
http://jsfiddle.net/jtbowden/UNZR5/1/
I have already spent some time adapting it (not a jquery programmer :/)
And all I need to add are captions to each picture.
Can someone help me just add captions to that same code?
Really appreciate it : )
You will need to enhance CSS more than this, but it is working as requested
http://jsfiddle.net/dU93C/
CSS
#fader {
position: relative;
width:500px;
height: 400px;
}
#fader div{
position: relative;
height: 400px;
width:400px;
overflow:hidden;
margin:0 auto;
}
#fader strong{
display:block;
position: absolute;
width:100%;
top:0;
left:0;
Background:#333;
Color:#fff;
padding:5px;
opacity:0.7;
filter:alpha(opacity=70);
}
.button {
background-color: green;
width: 50px;
height: 30px;
font-size: 20px;
line-height: 30px;
text-align: center;
position: absolute;
top: 30px;
}
#next {
right: 0;
}
#prev {
left: 0;
}
HTML
<div id="fader">
<a class="button" href="#" id="next">Next</a>
<a class="button" href="#" id="prev">Prev</a>
<div>
<strong>Image 1</strong>
<img src="http://dummyimage.com/600x400/000/fff.png&text=Image1"/>
</div>
<div>
<strong>Image 2</strong>
<img src="http://dummyimage.com/200x400/f00/000.jpg&text=Image2"/>
</div>
<div>
<strong>Image 3</strong>
<img src="http://dummyimage.com/100x100/0f0/000.png&text=Image3"/>
</div>
<div>
<strong>Image 4</strong>
<img src="http://dummyimage.com/400x400/0ff/000.gif&text=Image4"/>
</div>
<div>
<strong>Image 5</strong>
<img src="http://dummyimage.com/350x250/ff0/000.png&text=Image5"/>
</div>
</div>
JS
$(function() {
$('#fader div:not(:first)').hide();
var pause = false;
function fadeNext() {
$('#fader div').first().fadeOut().appendTo($('#fader'));
$('#fader div').first().fadeIn();
}
function fadePrev() {
$('#fader div').first().fadeOut();
$('#fader div').last().prependTo($('#fader')).fadeIn();
}
$('#fader, #next').click(function(e) {
fadeNext();
e.preventDefault()
});
$('#prev').click(function() {
fadePrev();
});
$('#fader, .button').hover(function() {
pause = true;
},function() {
pause = false;
});
function doRotate() {
if(!pause) {
fadeNext();
}
}
var rotate = setInterval(doRotate, 2000);
});
I'm trying to reproduce this and it's not working:
http://www.templatemonster.com/demo/44543.html
Here is my result: http://webs-it.com/callstar/
What I want is to navigate through the menu like the example I posted. I'm kinda new to javascript and I didn't manage to make it work.
Here is my code:
<html>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" >
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<style>
#block1 {
float:left;
width:1058px;
height:0px;
margin-left:-1058px;
margin-top:100px;
background-color:#fff;
position:relative;
}
#block2 {
width:1058px;
height:0px;
margin-left:-1058px;
margin-top:100px;
background-color:#fff;
position:relative;
}
#logo {
margin:0 auto;
width:502px;
height:259px;
margin-top:144px;
}
</style>
</head>
<body>
<div id="continut">
<div id="header">
<div id="social">
<img src="images/social/facebook.png" name="facebook" alt="."> <img src="images/social/ytube.png" name="ytube" alt="."> <img src="images/social/en.png" name="en" alt="."> <img src="images/social/cz.png" name="cz" alt=".">
</div>
</div>
<div id="block1">test test</div>
<div id="block2">test test</div>
<div id="logo" >
<img src="images/logo/logo_homepg.png">
</div>
<div id="meniu">
<img src="images/meniu/about.png" id="go1" name="about" alt="."><img src="images/meniu/photo.png" name="foto" id="go2" alt="."><img src="images/meniu/video.png" id="go3" name="video" alt="."><img src="images/meniu/ref.png" name="ref" id="go4" alt="."><img src="images/meniu/contact.png" name="contact" id="go5" alt=".">
</div>
</div>
<div id="footer"></div>
<script>
$( "#go1" ).click(function(){
$( "#block1" ).animate({ height: "300px" }, 1 )
.animate( { margin: "100px 0px" }, { queue: false, duration: 700 });
});
$( "#go2" ).click(function(){
$( "#block2" ).animate({ height: "300px" }, 1 )
.animate( { margin: "100px 0px" }, { queue: false, duration: 700 });
$( "#block1" ).animate({ height: "300px" }, 1 )
.animate({ margin: "100px 1558px" }, { queue: false, duration: 700 });
});
</script>
</body>
That was a fun challenge.
I created a similar effect for you here.
Check out the jsFiddle DEMO
P.S: All, HTML, CSS, and Javascript is new.
HTML
<div id="container">
<div id="content">
<div id="one"><p>One</p></div>
<div id="two"><p>Two</p></div>
<div id="three"><p>Three</p></div>
<div id="four"><p>Four</p></div>
</div>
<ul id="nav">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ul>
</div>
CSS
*{margin:0; padding:0; font-family: Helvetica}
#container{
width:100%;
height:600px;
overflow:hidden;
float:left;
background: url(http://webs-it.com/callstar/images/covers/electric_guitar2.jpg) center no-repeat;
}
p {
font-size:25px;
text-transform:uppercase;
text-align:center;
font-weight:bold;
color:#666;
margin-top:22%;
}
#content {
width:100%;
height:200px;
margin: 50px auto 0;
position:relative;
overflow:hidden;
}
#content > div {
display:block;
width:400px;
height:200px;
background:white;
position:absolute;
margin-left:100%;
/*left:-200px;*/
opacity: 0;,
top:40px
}
#nav {
list-style:none;
display:table;
margin:0 auto;
position:relative;
}
#nav li {
display:table-cell;
align:cen
display:inline-block;
padding:20px
}
#nav a {color:#fff; text-decoration:none;}
JS
$(function() {
var content = $('#content'),
contentHeight = content.height(),
nav = $('#nav'),
count = 0;
// on load content height is shorter
content.height(100);
nav.find('a').on('click', function() {
var $this = $(this),
parent = $this.parent(),
targetElement = $this.attr('href');
//Does the slide down animation once
if (count === 0) {
content.animate({'height': contentHeight }, function() {
parent.addClass('active');
//animate in
$(targetElement).animate({
left: '-=200px',
'margin-left': '50%',
opacity: 1
}, 500);
});
count = 1;
} else {
//only add active class if parent does not have it and then animate it
if ( !parent.hasClass('active') ) {
parent.addClass('active');
//animate in
$(targetElement).animate({
left: '-=200px',
'margin-left': '50%',
opacity: 1
}, 500);
//Gets older clicked element
var oldClickedElement = $('.active').not(parent).removeClass('active').find('a').attr('href');
//only if old click element exists the do the animation
if (oldClickedElement) {
//animate out + reset to start
$(oldClickedElement).animate({
left: 0,
'margin-left': '-50%',
opacity: 0
}, 500, function() {
$(oldClickedElement).css({
'margin-left' : '100%',
left: 0
});
});
}
}
}
return false;
});
});
Let me know if you have any questions.
I want to clone the first-child button from #navCotainer and insert it after the last button.
Now the Problem is: The script kind of inserts the first child 3 times. what do I have to do to get ir right? And also, what am I doing wrong?
of course a link to the fiddle http://jsfiddle.net/ygjDR/ and the code:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<span class="moveNav8 left8">left</span>
<div id="navContainer" style="width: 100%; overflow-y: auto;">
<div class="button">1</div>
<div class="button">2</div>
<div class="button">3</div>
<div class="button">4</div>
</div>
<script type="text/javascript">
$(document).on('click','.moveNav8', function() {
if($(this).hasClass('left8')) {
$('.button').animate({
left: '-=305'
}, 1000, function() {
$('#navContainer div.button:first-child').addClass("xxxx");
$('#navContainer ').children('div.button:first-child').clone().css("background-color","orange").insertAfter("#navContainer div.button:last-child");
});
}
});
</script>
<style type="text/css">
.button {
position: relative; float: left;
width:100px;
height:50px;
background-color:green;
margin-right:10px;
}
.moveNav8 {
position:absolute;
top:100px;
left:0px;
background-color:red;
width:40px;
height:40px;
}
.moveNav8.right8 {
left:100px;
}
</style>
Try this:
http://jsfiddle.net/gtttG/
You need to add a check for $(".button:animated").length === 0.
Animation callback is invoked for every item, appending a button 4 times. Instead execute callback only once after the last animation using deferred pattern:
$(document).on('click', '.moveNav8', function () {
if ($(this).hasClass('left8')) {
$('.button').animate({
left: '-=305'
}, 1000).promise().done(function () {
$('#navContainer div.button:first-child').addClass("xxxx");
$('#navContainer').children('div.button:first-child').clone().css("background-color", "orange").insertAfter("#navContainer div.button:last-child");
})
}
});
http://jsfiddle.net/ygjDR/3/