How do you make a link that when pressed, displays more information about something without reloading the page? (i believe it is called overflow?)
an example would be here:
https://market.android.com/details?id=com.jiwire.android.finder&feature=featured-apps
click the MORE button under the Description section, and more description is showed and the entire webpage's content slides down WITHOUT need to reload
Thanks!
Make use of this
<!DOCTYPE html>
<html>
<head>
<style>
div { background:#de9a44; margin:3px; width:80px;
height:40px; display:none; float:left; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
Click me!
<div></div>
<div></div>
<div></div>
<script>
$(document.body).click(function () {
if ($("div:first").is(":hidden")) {
$("div").slideDown("slow");
} else {
$("div").hide();
}
});
</script>
<script>
$(document.body).click(function () {
if ($("div:first").is(":hidden")) {
$("div").show("slow");
} else {
$("div").slideUp();
}
});
</script>
</body>
</html>
Related
Any opinions on this? When the user presses the button the initially hidden div must show itself on the page.
<!DOCTYPE html>
<html>
<head>
<style>
div {
display: none;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
function show() {
$("div").toggle();
}
</script>
</head>
<body>
<p>Animals are cute!</p>
<div><p>Some text gonna blow up some pixels!</p></div>
<button onclick="show()">Click</button>
</body>
</html>
The exactly written error in the Console:
ReferenceError: show is not defined[Learn More
Move the inline script into its own tag. You can't use an external script and inline script in the same tag.
So:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function show() {
$("div").toggle();
}
</script>
function show() {
$(".any-text").toggle();
}
.any-text {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>
<p>Animals are cute!</p>
<div class="any-text"><p>Some text gonna blow up some pixels!</p></div>
<button onclick="show()">Click</button>
</body>
</html>
I want to click a button on my page then another div toggle on and load in that div another page, but it doesn't work.
HTML:
<html>
<head>
<script type="text/javascript" src="js/jquery-1.7.2.min_1.js"></script>
<script>
$(document).ready(function() {
$('#clickme').click(function() {
$('#me').animate({
height: 'toggle'
}, 1000
);
$("#me").load("page2.html")
});
});
</script>
</head>
<body>
<div id="clickme" style="color: #FFFFFF;">
Click here
</div>
<div id="me" style="border:1px solid #000; width:900px; height:300px;">
</div>
</body>
</html>
I believe your function can be simplified to use the normal callback of toggle or slidetoggle
$(function() {
$('#clickme').on("click",function() {
$('#me').toggle(function() {
$(this).load("page2.html");
});
});
});
But you might want to load before toggling:
$(function() {
$('#clickme').on("click",function() {
$('#me').load("page2.html",function() {
$('#me').slideToggle();
});
});
});
I want to show the div with id #flower when clicking on the link with id #button but it doesnt work. Heres is the code i wrote.. i made also a jsbin page to show you
any suggestions?
http://jsbin.com/xefanaji/3/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="front">
<div><p>Button</p></div>
</div>
<div id="flower">
<img src="http://2.bp.blogspot.com/-Gaz8V9dP5O0/UUjtKJPofuI/AAAAAAAALDQ/boET2Ns34aU/s320/blooming-flowers-35.jpg" alt="flower"/>
</div>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
$(document).ready(
function(){
$("#button").click(function () {
$("#flower").show("slow");
});
});
</script>
</body>
</html>
css
#button{
position:relative;
height:30px;
width:60px;
background-color:lightyellow;
left:40px;
top:40px;
}
#flower{
display:none;
position:relative;
top:-600px;
left:50px;
z-index:0;
}
#front {
z-index:1;
position:relative;
top:100px;
height:600px;
width:100%;
background-color:lightblue;
}
if i am not wrong.. you need to add id to your button ,if (<a ..>Button</a>) is the element you are talking about.
<div><p>Button</p></div>
//-^^^^^^^^^^----here
$("#button").click(function (e) {
e.preventDefault();
$("#flower").show("slow");
});
with CSS you have, i am sure you forget to add id to that a link
well few more thing,
always load script in your <head> section, and you don't need to add src in script tag
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
..
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
....
....
<script>
$(document).ready(
function(){
$("#button").click(function () {
$("#flower").show("slow");
});
});
</script>
Try this
<div id="front">
<div><p><a id="button" href="">Button</a></p></div>
</div>
<div id="flower">
<img src="http://2.bp.blogspot.com/-Gaz8V9dP5O0/UUjtKJPofuI/AAAAAAAALDQ/boET2Ns34aU/s320/blooming-flowers-35.jpg" alt="flower"/>
</div>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(
function(){
$("#button").click(function (e) {
e.preventDefault();
$("#flower").show("slow");
});
});
</script>
DEMO
Put the jQuery library in the head section of your document like below
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
If you need button you can use span instead of anchor e.g.
<span class="button">Button</span>
then add a little styling
.button {
font-size: 12px;
color: #333;
}
.button:hover {
color: #ddd;
}
and then put this script just before </body> tag
<script>
$(function() {
$(".button").click(function () {
$("#flower").show("slow");
});
});
</script>
You could use the revised jQuery below to accomplish this, the reason your code isnt working is because your link doesnt have the id button set.
$('#front a:first').on('click',function(e){
e.preventDefault();
$('#flower').show();
})
You are missing id #button for that link.
<a id="button" href="">Button</a>
Hello I am trying to create sliding out tabs on this website: http://imaginationmuzic.com/
I am referring to the red 'Contact Us' and blue 'Twitter' tabs at the left and right of the site.
Currently the Contact Us tab opens up in a top to down motion; I would like it to open up from left to right like a sliding out tab.
Here is the code I used in the header:
$(document).ready(function(){
$(".btn-slide2").click(function(){
$("#panel2").slideToggle("slow");
$(this).toggleClass("active"); return false;
});
I also would like the opposite to be done for the Twitter tab (have it open left to right).
Any help would be appreciated.
Some crude js code I made to demonstrate.
<!DOCTYPE HTML>
<html>
<head>
<!--Add style sheet-->
<link rel="stylesheet" type="text/css" href="soc.css">
<!--Add jquery-->
<script src="jquery-1.10.2.js">
</script>
<!--Add script for this page-->
<script src="soj.js">
</script>
</head>
<body>
<div id="container">
<div id="panel"> </div>
<div id="contact"> </div>
</div>
</body>
<html>
-------------css----------
#panel{
height:500px;
width:200px;
background-color:#EE4488;
}
#contact{
position:relative;
top:-500px;
left:200px;
width:10px;
height:50px;
background-color:#22EEFF;
}
#container{
position:relative;
left:-200px;
}
------------JS---------
$(document).ready(function(){
var pos='in';
$("#contact").click(function(){
if(pos=='in'){
$("#container").animate({left:'0px'
});
pos='out';
}
else
{
$("#container").animate({left:'-200px'
});
pos='in';
}
});
});
I'm new to JQuery, and despite reading through the guide several times, I can't find the problem.
The following functions are not getting fired when I click on the button:
function enable(){
alert("Enable Working!");
}
function disable(){
alert("Disable Working!");
}
$("#enable").click(function(){
$("#enable").hide();
});
$("#disable").click(function(){
disable();
});
And the html page. I don't see any mistakes here either
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>popup</title>
<style>
#enable{
color:green;
position:relative;
top:20px;
}
#disable{
color:red;
position:relative;
top:25px;
}
body{
height: 100px;
}
</style>
</head>
<body id="popup">
<input id="enable" type="button" value="Enable">
<br />
<input id="disable" type="button" value="Disable">
<script src="popup.js"></script>
<script src="jquery.js"></script>
</body>
<html>
What I'd like is for the the enable function to run when I click the enable button. I'd like the disable function to run when I click the disable button. The alerts are there to test if it's working.
Load the jQuery file first, change the order of your files:
<script src="jquery.js"></script>
<script src="popup.js"></script>
Maybe something like this:
function enable(){
alert("Enable Working!");
}
function disable(){
alert("Disable Working!");
}
$("#enable").click(enable);
$("#disable").click(disable);
And as someone else mentioned, reverse the script includement:
<script src="jquery.js"></script>
<script src="popup.js"></script>
Your code looks good, just change the code inside the #enable click to run the function:
Demo
$("#enable").click(function(){
enable();
});
$("#disable").click(function(){
disable();
});
If you want to hide the button, putt it inside the function:
function enable(){
alert("Enable Working!");
$("#enable").hide();
}
Add this to load your code when the page loads:
$(document).ready(function(){
//your code
});
The jQuery script file can be loaded from an online source. If you want that the code is <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>. Load it before your other .js files. If the need jQuery.
Change it to this:
function enable(){
alert("Enable Working!");
}
function disable(){
alert("Disable Working!");
}
$(document).ready(function() {
$("#enable").click(function(){
enable();
});
$("#disable").click(function(){
disable();
});
});
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>popup</title>
<style>
#enable{
color:green;
position:relative;
top:20px;
}
#disable{
color:red;
position:relative;
top:25px;
}
body{
height: 100px;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
});
function enable(){
alert("Enable Working!");
}
function disable(){
alert("Disable Working!");
}
$("#enable").click(function(){
enable();
});
$("#disable").click(function(){
disable();
});
});
</script>
</head>
<body>
<input id="enable" type="button" value="Enable">
<br />
<input id="disable" type="button" value="Disable">
</body>
</html>