Revealing and hiding specific div with iframe inside with button - html

I´m just trying to do website for family member. I´ve got base html with css done, but there is one issue. I need to implement to page changing iframe that is linked to two kinds of forms in php. Right now I´ve figured out code for change hrefs, but these iframes have different heights so I want to close both of them into divs and reveal first or second with buttons.
Here is the code so far:
<section id="predplatne" class="clearfix">
<div class="predplatne_in">
<h2>Text</h2>
<div class="vyber">
<button class="button">1</button>
<button class="button">2</button>
</div>
<div class="box">
<div class="in">
<iframe allowfullscreen frameborder="0" height="1700" id="frame" name="frame" src="http://www.php" width="480"></iframe>
</div>
</div>
</div>
</div>

You can use JS for that. From what I've understood, you want to show an <iframe> when the button is clicked?
First off, create your <iframe>s and set both of their CSS display values to none, like so:
<div class="iframes">
<iframe allowfullscreen style="display: none" frameborder="0" height="300" width="480" name="frame1" src="http://example.com"></iframe>
<iframe allowfullscreen style="display: none" frameborder="0" height="300" width="240" name="frame2" src="http://thedragonring.me"></iframe>
</div>
Then, add some <button>s with a little script in their onclick attributes that will toggle whether the display attribute of the corresponding <iframe> is set to none or block, like so:
<div class="buttons">
<button onclick="
const el = document.querySelector('.iframes [name=frame1]');
el.style.display = el.style.display === 'none' ? '' : 'none';
">
Frame 1 (example.com)
</button>
<button onclick="
const el = document.querySelector('.iframes [name=frame2]');
el.style.display = el.style.display === 'none' ? '' : 'none';
">
Frame 2 (thedragonring.me)
</button>
</div>
Alternatively, you could add a single button that will toggle between the 2 iframes:
<button onclick="
const frame1 = document.querySelector('.iframes [name=frame1]'),
frame2 = document.querySelector('.iframes [name=frame2]'),
prev = frame1.style.display;
frame1.style.display = prev === 'none' ? '' : 'none';
frame2.style.display = prev === 'none' ? 'none' : '';
">
Toggle
</button>
Basically, all these snippets of JS do is inverse the display attribute of the target <iframe>. You can see a demo # http://jsfiddle.net/TheDragonRing/4bzrvnyh/

You can achieve with some methods below
#if1, #if2{
display:none;
}
#btn1:active ~ div #if1, #btn2:active ~ div #if2{
display:block;
}
#rd1:checked ~ div #if1, #rd2:checked ~ div #if2{
display:block;
}
#cb1:checked ~ div #if1, #cb2:checked ~ div #if2{
display:block;
}
<!-- Reveal with active button -->
<button id="btn1">Reveal Frame 1</button>
<button id="btn2">Reveal Frame 2</button>
<br>
<!-- Reveal with checked radio -->
<input type="radio" id="rd1" name="reveal">
<label for="rd1">Reveal Frame 1</label>
<input type="radio" id="rd2" name="reveal">
<label for="rd2">Reveal Frame 2</label>
<br>
<!-- Reveal with checked checkbox -->
<input type="checkbox" id="cb1">
<label for="cb1">Reveal Frame 1</label>
<input type="checkbox" id="cb2">
<label for="cb2">Reveal Frame 2</label>
<div>
<iframe width="100px" id="if1" src="http://google.com">Test</iframe>
<iframe width="200px" id="if2" src="http://amazon.com">Test</iframe>
</div>
The easiest way is use javascript than just html and css
Hope it helps

Related

Show and hide imges on tap button in AMP

Is possible to show one image and hide multiple images on button tap i AMP?
For exaplme, I have a 4 buttons (button1, button2, button3 and button4) and have 4 images (img1, img2, img3, img4). And I would like to do something like that, hit button1 and show img1, hit button2 show img2 but hide img1 and etc.
In simple way hit button to show image and hide image witch is currently on screen.
I tried to do it, but im stuck on something like this. But it won't works correctly.
<button class="button1" on="tap:img1.toggleVisibility">BUTTON1</button>
<button class="button2" on="tap:img2.toggleVisibility">BUTTON2</button>
<button class="button3" on="tap:img3.toggleVisibility">BUTTON3</button>
<button class="button4" on="tap:img4.toggleVisibility">BUTTON4</button>
<div>
<div id="img1" style=" position: absolute" hidden >
<amp-img src="img1.jpg" width="600" height="600"> </amp-img>
</div>
<div id="img2" style=" position: absolute" hidden >
<amp-img src="img2.jpg" width="600" height="600"> </amp-img>
</div>
<div id="img3" style=" position: absolute" hidden >
<amp-img src="img3.jpg" width="600" height="600"> </amp-img>
</div>
<div id="img4" style=" position: absolute" hidden >
<amp-img src="img4.jpg" width="600" height="600"> </amp-img>
</div>
</div>
I've tired with on="tap:AMP.setState({ hide: true })" and on="tap:AMP.setState({ hide: false })" but it works only for two images.
For a long time the question was unanswered, I will try to help and I hope the question is still relevant.
If I understand correctly, you want to display only image related to button id clicked at once. For simplicity of the example, I will not use images directly. Instead, we use multi-colored div's. The solution is binding hidden property to exact Id. Feel free to play with below enhanced code and css, and images if you like:
.container{
display: flex;
margin-left: 100px;
}
.box{
width: 30px;
height: 30px;
margin: 25px;
padding: 5px;
color: azure;
font-weight: 900;
}
.img1{
background: red;
}
.img2{
background: green;
}
.img3{
background: blue;
}
.img4{
background: yellow;
}
<button class="button1" on="tap:AMP.setState({id:1})">BUTTON1</button>
<button class="button2" on="tap:AMP.setState({id:2})">BUTTON2</button>
<button class="button3" on="tap:AMP.setState({id:3})">BUTTON3</button>
<button class="button4" on="tap:AMP.setState({id:4})">BUTTON4</button>
<div class="container">
<div id="img 1" class="img1 box" hidden [hidden] = "id == 1 ? false : true" >
img1
</div>
<div id="img 2" class="img2 box" hidden [hidden] = "id == 2 ? false : true" >
img2
</div>
<div id="img 3" class="img3 box" hidden [hidden] = "id == 3 ? false : true">
img3
</div>
<div id="img 4" class="img4 box" hidden [hidden] = "id == 4 ? false : true">
img4
</div>
</div>
Warm Regards,
V.

When I click on a button focus goes to text area

I'm very new to CSS and HTML and I'm facing a very strange issue here, I have text area in my html as below.
<div class="ContentBox BPMSectionBody LastContentBox noHeader" id="div_3_1_1_2_11_1_1_1_1_1_1_10_1" data-view-managed="false">
<div class="Text_Area fullWidthTextArea CoachView CoachView_hidden CoachView_show" id="div_3_1_1_2_11_1_1_1_1_1_1_10_1_1" data-eventid="" data-viewid="Text_Area8" data-config="config99" data-bindingtype="String" data-binding="local.userAction.comments"
data-type="com.ibm.bpm.coach.Snapshot_7a0c03cc_ccef_4582_a1bc_7ccc8e9be488.Text_Area">
<div class="textLabel">
<label class="text controlLabel" id="div_3_1_1_2_11_1_1_1_1_1_1_10_1_1_label">Enter Cancellation Comments</label>
<div class="coachValidationDiv">
<img class="coachValidationImg smallImg CoachView_hidden" role="alert" alt="Error" src="/teamworks/webasset/2064.7a0c03cc-ccef-4582-a1bc-7ccc8e9be488/W/Error_icon_24x24.png">
<span class="coachValidationText" style="visibility: hidden;">!</span>
</div>
</div>
<textarea tabindex="0" class="dijitTextBox dijitTextArea dijitExpandingTextArea BPMTextAreaFont" id="dijit_form_Textarea_16" aria-labelledby="div_3_1_1_2_11_1_1_1_1_1_1_10_1_1_label" style="-ms-overflow-x: auto; -ms-overflow-y: hidden; box-sizing: border-box;"
rows="1" data-dojo-attach-point="focusNode,containerNode,textbox" widgetId="dijit_form_Textarea_16" autocomplete="off" value=""></textarea>
</div>
</div>
And a button as below :
<div class="Button pageFlowButton CoachView CoachView_show" id="div_3_1_1_2_12_1_2" data-eventid="boundaryEvent_17" data-viewid="Button10" data-config="config83" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_7a0c03cc_ccef_4582_a1bc_7ccc8e9be488.Button">
<button class="BPMButton BPMButtonBorder" type="button">Continue With Selected Action</button>
</div>
when I start typing in textarea and having my cursor still in the textarea and i click on button for the first time instead of action being taken, text area gets focused.
When I click button second time it works fine.
Can any body please help,what can be the possible reason here??
In case you are using jQuery, I guess you should use:
$('.Text_Area').click(function(noFocus){
noFocus.preventDefault();
});

Using a button to move to a certain ID on a page

So I'm making a website (suprise, suprise) and I have a button on the top of the page, and when I click it, it does nothing. I am wondering how to fix it.
The button
<button class="Learn-Link" href="#VideoSlide">Learn How
<div class="Learn-Triangle"></div>
</button>
And the part I want to travel to
<div class="Slide" id="VideoSlide">
<!--More code here, but not relevant-->
</div>
button doesn't have an href attribute you need to add an a tag inside your button
#VideoSlide{
position: relative;
top:1000px;
height: 100px;
background: pink
}
<button class="Learn-Link" >Learn How
<div class="Learn-Triangle"></div>
</button>
<div class="Slide" id="VideoSlide">
<!--More code here, but not relevant-->
</div>
You can trigger button by using javascript
Eg:-
<button type="button" onclick="alert('Hello world!')">Click Me!</button>

Is there a way I can connect content with multiple divs?

I'm not sure how to ask this question so below is an visualization of what I want to achieve.
Please let me know if there is anything I can clarify!
Clarification:
At slide one, image 01 and image 02 are visible. Only when the person clicks on the images does the text and title div become visible. More importantly, the text box must be coherent with the page-wrapper. For example, if I were to set the text div to float:right, it will float on the right side of the page-wrapper.
Thank you in advance.
You need some javascript to get this behaviour i think. You can try something like this:
Everything in a little bit pseudo code.
HTML:
<img src="..." class="img1 clickImage">
<img src="..." class="img2 clickImage">
<div class="imageTitles">
<div class="img1 imgTitle">TITLETEXT</div>
<div class="img2 imgTitle">TITLETEXT</div>
</div>
<div class="imageInformations">
<div class="img1 imgInformation">INFORMATION img1</div>
<div class="img2 imgInformation">INFORMATION img2</div>
</div>
And some jQuery:
jQuery('.clickImage').on('click', function() {
var imgNumber = jQuery(this).getClass().replace('clickImage', '');
jQuery('imageTitles .imgTitle').hide(); //hide all image Titles
jQuery('imageTitles .imgTitle.' + imgNumber).show(); //show title for e.g. img1
//repeat this for imgInformation
});
Everything a little bit rough, but i hope it gives you an idea what you need to do.
EDIT:
Code now looks like this:
HTML:
<img src="http://media.tumblr.com/tumblr_mcepyv1Qfv1ru82ue.jpg" class="img1 clickImage">
<img src="http://media.tumblr.com/tumblr_mcf11pk4nj1ru82ue.jpg" class="img2 clickImage">
<div id="page-wrap">
<div class="imageTitles">
<div class="img1 imgTitle">TITLETEXT</div>
<div class="img2 imgTitle">TITLETEXT</div>
</div>
<div class="imageInformations">
<div class="img1 imgInformation">INFORMATION img1</div>
<div class="img2 imgInformation">INFORMATION img2</div>
</div>
</div>
JS:
jQuery('.imageTitles .imgTitle').hide();
jQuery('.imageInformations .imgInformation').hide();
jQuery('.clickImage').on('click', function () {
var imgNumber = jQuery(this).attr("class").replace('clickImage', '');
jQuery('.imageTitles .imgTitle').hide(); //hide all image Titles
jQuery('.imageTitles .imgTitle.' + imgNumber).show(); //show title for e.g. img1
jQuery('.imageInformations .imgInformation').hide();
jQuery('.imageInformations .imgInformation.' + imgNumber).show();
});
There are many ways to achieve this.
1) with every thing static, ie info about image is already available in the page in different div's.
ex: working
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.switch').hide();
});
function myInfo(myId)
{
$('.switch').hide();
$('#title'+myId).show();
$('#description'+myId).show();
}
</script>
<table>
<tr>
<td>
<!-- Images -->
<img onclick="return myInfo('1')" id='image1' height="60" width="60" src="http://static3.businessinsider.com/image/52cddfb169beddee2a6c2246/the-29-coolest-us-air-force-images-of-the-year.jpg" alt="Image1"><br/>
<img onclick="return myInfo('2')" id='image1' height="60" width="60" src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR6I83EILo3XKIsqZ-0Q5JAEw38xGzsy1g_iKImqjBrMVaOHYb4Zg" alt="Image2">
</td>
<td>
<div id="title1" class="switch"> Image 1</div>
<div id="title2" class="switch"> Image 2</div>
</td>
<td>
<div id="description1" class="switch"> Information about Image 1 </div>
<div id="description2" class="switch"> Information about Image 2 </div>
</td>
</tr>
</table>
2) You can achieve this using AJAX calls for image information, in this case only 1 div for title and 1 for info is enough i you want to use else 1 div is enough. On click of image make an AJAX call to get the image info and display it in the div.
These are 2 ways and there are many more.

mobile device back button jquery mobile bug page not styled

when I'm using my phone to test the app, I use the back device button to show the previous page this is working with all the pages except one page that shows a not styled page when trying to get to the pervious page so there somthing Odd. Here a briefe explanation.
there is 3 page #main_menu , #first_map , #second_map
when I'm into the #second_map page it should go to the #first_page when I press back button
but actually its showing the #main_menu page with not css styling.
could you plz tell me what is the problem an how we can fix it thank you in advance .
I provide the source code :
this is the main_page
</div>
<h2 id="thx_msg" style="margin:0 auto;"></h2>
<div class="grid2">
<div class="first" id="search_btn">
<div>
<img src="images/loupe.jpg"/>
<div>
</div>Search for a Spot</div>
</div>
<div class="second" id="submit_spot_btn">
<div>
<img src="images/spot.jpg"/>
</div>
<div>Submit a spot</div>
</div>
</div>
<ul style="margin:0 auto;" class="spaced_list" style="widht:280px;" >
<li><input type="button" data-role="none" value="Account info" class="btn" style="margin:0 auto;" id="main_page_account_info"/></li>
<li><input type="button" data-role="none" value="Log Out" class="btn" style="margin:0 auto;"id="main_page_log_out"/></li>
</ul>
</div>
here is the first_map page is named spot_page
<div data-role="page" id="spot_page" data-theme="b">
<div data-role="header" style="overflow:hidden;">
<img class="logo_icon" src="images/logo_icon.png">
</div><!-- header -->
<div class="clear"></div>
<div id="search_form_holder" style="margin:0px 25px" >
<p class="center" style="font-size:16px;font-weight:bold;">
Search for a Spot
</p>
<ul class="some_space" style="margin:0 auto;
margin-left:auto;
margin-right:auto;
align:center;
text-align:center;
width:280px;">
<li><input type="text" id="address_zip" class="field black" placeholder="Address/Zip Code"/></li>
<li id="to"></li>
<li><input type="button" data-role="none" style="width:200px;margin:15px auto;" id="search_spot_btn" class="btn" value="Search for a Spot"></li>
</ul>
<div id="hidden_scroller" style="display:none">
<select id="distance" name="Within">
<option value="1">1 Mile</option>
<option value="3">3 Miles</option>
<option value="5">5 Miles</option>
<option value="10">10 Miles</option>
</select>
</div>
</div><!-- search form -->
<div id="first_map" style="width: 100%;
height: 247px;border:1px solid black;margin:0 auto">
</div>
</div><!-- split view -->
and finally the second map here :
<div data-role="page" id="nearby_page">
<div data-role="header" style="overflow:hidden;">
<img class="logo_icon" src="images/logo_icon.png">
</div><!-- header -->
<div class="clear"></div>
<div class="second_header">Spots nearby</div>
<div id="map" style="width: 100%;
height: 398px;border:1px solid black;margin:0 auto">
</div>
</div>
As you can see the pages are separate from each other.
I have a last question could a navigation plugin help to fix the problem like jquery history plugin and thanks for your help.
Make sure to have your pages on different separate pages. If not these kind of errors will occur. Mostly, you will encounter abnormal navigation error. That is what I have experienced in my experience.
BTW, you should show more of your code for people here to help you out.
Update
PhoneGap and Android's back button do behaves odd. What I have done in my application is disabled the back button and given the soft back button on the top header. Simple history.back() will do the magic for back buttons.
You can disable as follows.
$(function(){
document.addEventListener("deviceready", onDeviceReady, false);
})
// PhoneGap is loaded and it is now safe to call PhoneGap methods
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {
console.log("Back button pressed but nothing happened");
}
Anyway this is my approach. You may choose to be different.