The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Button Pressed Moves Input and Button down the page, Buttons
HelloWorld_
post Jul 16 2021, 07:45 AM
Post #1





Group: Members
Posts: 3
Joined: 16-July 21
Member No.: 28,015



New to HTML and CSS, but have setup a very simple Input/Button test page.

When you press the button a random audio is played.

However also when you press the button, both the input and button field move down the page slightly. Any ideas what I could be doing wrong here?


<section>
<!----BTN Start.-->
<!----For some reason need to keep span id player above the button or sounds wont play.-->
<span id='player'></span>

<input type="text" id="searchinput" spellcheck="true" class="mainsearch" autofocus>
</section>

<section>
<button id="searchbutton" class="mainsearchbutton rotate" onclick="playRandomSound();">Search Now</button>
</section>
<!----BTN END.-->



.mainsearch {
display: block;
margin-left: auto;
margin-right: auto;

width: 25rem;
position: relative;
height: 2.38rem;
border-radius: 25rem;
background-color: #05F4B7;
color: #12151F;
font-family: roboto;
font-size: 20px;
font-weight: 500;
border: 0px;
padding-left: 2rem;
padding-right: 2rem;
margin-bottom: 3rem;
outline: none;
}

.mainsearchbutton {
display: block;
margin-left: auto;
margin-right: auto;

width: 29rem;
position: relative;
height: 2.5rem;
border-radius: 25rem;
background-color: #05F4B7;
color: #12151F;
font-family: roboto;
font-size: 20px;
font-weight: bolder;
border: 0px;

transform: rotate(-5deg);
transition-duration: 0.5s;
}


.mainsearchbutton:hover {
background-color: #937aff;
color: white;
transition-duration: 0.5s;

}
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jul 16 2021, 10:08 AM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Nothing moves when I click the button with what you gave us. What do you have more than that? Maybe the script does something more than play a sound file?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
HelloWorld_
post Jul 16 2021, 10:12 AM
Post #3





Group: Members
Posts: 3
Joined: 16-July 21
Member No.: 28,015



QUOTE(pandy @ Jul 16 2021, 10:08 AM) *

Nothing moves when I click the button with what you gave us. What do you have more than that? Maybe the script does something more than play a sound file?



Found the culprit.

document.getElementById('searchbutton').onclick = function () {
document.getElementById('searchinput').focus();
};

Just not sure why it moves the section down.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jul 16 2021, 10:35 AM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Well, focus() will focus the search field and place the cursor there. The page will be scrolled if needed.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
HelloWorld_
post Jul 17 2021, 09:22 AM
Post #5





Group: Members
Posts: 3
Joined: 16-July 21
Member No.: 28,015



QUOTE(pandy @ Jul 16 2021, 10:35 AM) *

Well, focus() will focus the search field and place the cursor there. The page will be scrolled if needed.

Hi Pandy, I removed this code and still get the error.

document.getElementById('searchbutton').onclick = function () {
document.getElementById('searchinput').focus();
};

Do you see anything wrong in this JS below that could be the cause for moving the input/search button down the page. When I turn it off the error is gone.

function playRandomSound() {
var sounds = [
"pur-once-btn-click (1).mp3",
"famous-quotes (2).mp3"
];

var soundFile = sounds[Math.floor(Math.random() * sounds.length)];
document.getElementById("player").innerHTML = "<embed src=\"" + soundFile + "\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";


}

This post has been edited by HelloWorld_: Jul 17 2021, 09:23 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Jul 17 2021, 06:39 PM
Post #6


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



QUOTE(HelloWorld_ @ Jul 17 2021, 04:22 PM) *

Hi Pandy, I removed this code and still get the error.

document.getElementById('searchbutton').onclick = function () {
document.getElementById('searchinput').focus();
};


But you said that was the culprit?

QUOTE
Do you see anything wrong in this JS below that could be the cause for moving the input/search button down the page. When I turn it off the error is gone.


No. You use attributes that belong to the old non standard EMBED and I don't know if browsers support them anymore, but if it works it works. EMBED itself is standard now with HTML5, but not the old attributes. But I don't see how that could make anything jump.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 03:49 AM